From ef0fe8d0093bffceb537c2a3f1b3a46ced78fb0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 Sep 2023 21:15:33 +0000 Subject: [PATCH 001/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6b798e8..2df283c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 1c0278f..60b27c8 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 267c50f8c1c487cddce4f99c16b9dd7a48f6908d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 Sep 2023 21:17:23 +0000 Subject: [PATCH 002/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 161 - lib/options.js | 39 - lib/slice_start.js | 59 - lib/slice_strides.js | 60 - package.json | 69 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 35 - 44 files changed, 6208 insertions(+), 5083 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html 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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 7ad6bb6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 9ef1395..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 df02b32..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var l=function(i,a){return function(){return a||i((a={exports:{}}).exports,a),a.exports}};var g=l(function(W,q){ -var M=require('@stdlib/ndarray-base-sub2ind/dist');function N(i,a,u,s){var e,r,t;for(e=i.data,r=[a,u,s],t=0;t0&&(n=K(n.length))}else n=A(o);return E(n)===0?Q(c,r,h(n,d),v):(e=L(t,s,e,v,O(o,t,s,0),"throw"),n=h(n,d),n.length===0?new c(r,i.data,[],[0],e,v,m()):(s=P(o,s,d),new c(r,i.data,n,s,e,v,m())))}k.exports=T -});var U=D();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 9e8c673..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,EAAU,QAAS,8BAA+B,EAmBtD,SAASC,EAAYC,EAAOC,EAAOC,EAASC,EAAS,CACpD,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOJ,EAAM,KACbK,EAAO,CAAEJ,EAAOC,EAASC,CAAO,EAC1BG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,EAAK,KAAMD,EAAME,CAAE,EAAE,KAAM,EAE5B,OAAAD,EAAK,KAAM,OAAQ,EACZP,EAAQ,MAAO,KAAMO,CAAK,CAClC,CAKAR,EAAO,QAAUE,IC1DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAY,QAAS,gCAAiC,EACtDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQpB,EAAsBa,CAAE,EAGhCW,EAAKzB,EAAqBc,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKzB,EAAqBc,EAAGK,EAAO,EAAM,EAG1CK,EAAKtB,EAAYuB,CAAG,EAGfnB,EAAOH,EAAMqB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKpB,EAAOoB,EAAG,MAAO,EAExB,MAECA,EAAKtB,EAAYuB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOf,EAAMqB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAASZ,EAAWc,EAAOH,EAASC,EAAQG,EAAOZ,EAAYiB,EAAIN,EAAOH,EAAS,CAAE,EAAG,OAAQ,EAGhGQ,EAAKrB,EAAMqB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAX,EAAO,QAAUa,ICnGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sub2ind", "sliceStart", "slice", "shape", "strides", "offset", "data", "args", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "vind2bind", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af94fe3 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function l(l,h,p){var j,f,c,u,v,b,g,y,x,w;if(c=l.dtype,u=l.shape,j=l.strides,f=l.offset,v=l.order,g=u.length,h.ndims!==g)throw new RangeError(a("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",u.join(","),h.ndims));if(y=l.constructor,0===g)return new y(c,l.data,u,j,f,v,{readonly:!0});if(b=s(h),(w=e(h,u,!0)).code){if(p)throw new RangeError(a("invalid argument. Slice exceeds array bounds. Array shape: (%s).",u.join(",")));w=e(h,u,!1),x=r(w),d(n(x,b))>0&&(x=t(x.length))}else x=r(w);return 0===d(x)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,m(s,0),r,i,0,n,{readonly:!0})}(y,c,n(x,b),v):(f=i(u,j,f,v,function(e,s,r,n){var t,i,d;for(t=e.data,i=[s,r,n],d=0;d\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MODULES //\n\nimport sub2ind from '@stdlib/ndarray-base-sub2ind';\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","vind2bind","args","i","push","start","sub2ind","apply","sliceStart","rdims","out","j","step","slice2strides"],"mappings":";;27BAgFA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EChFlD,CAENY,UAAY,IDuFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GElGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFwFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EAASyB,EAAWvB,EAAOH,EAASC,EAAQG,EGpG7C,SAAqBR,EAAOO,EAAOH,EAASC,GAC3C,IAAIc,EACAY,EACAC,EAIJ,IAFAb,EAAOnB,EAAMmB,KACbY,EAAO,CAAExB,EAAOH,EAASC,GACnB2B,EAAI,EAAGA,EAAIb,EAAKL,OAAQkB,IAC7BD,EAAKE,KAAMd,EAAMa,GAAIE,OAGtB,OADAH,EAAKE,KAAM,SACJE,EAAQC,MAAO,KAAML,EAC7B,CHwFoDM,CAAYxB,EAAIN,EAAOH,EAAS,GAAK,SAMrE,KAHnBQ,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECvH7C,CAENY,UAAY,KDwHbhB,EI9GD,SAAwBJ,EAAOI,EAASkC,GACvC,IAAInB,EACAoB,EACAP,EACAQ,EAIJ,IAFArB,EAAOnB,EAAMmB,KACboB,EAAM,GACAP,EAAI,EAAGA,EAAIM,EAAMxB,OAAQkB,IAC9BQ,EAAIF,EAAON,GACXO,EAAIN,KAAM7B,EAAQoC,GAAKrB,EAAKqB,GAAGC,MAEhC,OAAOF,CACR,CJiGWG,CAAe7B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC7H9C,CAENY,UAAY,KD4Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 2df283c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index cad2904..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); - - -// MAIN // - -/** -* Resolves the linear index of the first element indexed by a normalized multi-slice. -* -* ## Notes -* -* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - index offset -* @returns {NonNegativeInteger} linear index of the first element -*/ -function sliceStart( slice, shape, strides, offset ) { - var data; - var args; - var i; - - data = slice.data; - args = [ shape, strides, offset ]; - for ( i = 0; i < data.length; i++ ) { - args.push( data[ i ].start ); - } - args.push( 'throw' ); - return sub2ind.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 60b27c8..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,48 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-sub2ind": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..891ae2e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6ebc435..0000000 --- a/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 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(); -}); - -// TODO: add tests From 9a0484388d4c1cebb96988f309838835fce3a706 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 Sep 2023 23:16:20 +0000 Subject: [PATCH 003/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6b798e8..2df283c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 4cde4ad..d619b40 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d5aa8df3db7eaaa808ab5c79bbfca60d7a1bd5e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 Sep 2023 23:16:50 +0000 Subject: [PATCH 004/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af94fe3..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function l(l,h,p){var j,f,c,u,v,b,g,y,x,w;if(c=l.dtype,u=l.shape,j=l.strides,f=l.offset,v=l.order,g=u.length,h.ndims!==g)throw new RangeError(a("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",u.join(","),h.ndims));if(y=l.constructor,0===g)return new y(c,l.data,u,j,f,v,{readonly:!0});if(b=s(h),(w=e(h,u,!0)).code){if(p)throw new RangeError(a("invalid argument. Slice exceeds array bounds. Array shape: (%s).",u.join(",")));w=e(h,u,!1),x=r(w),d(n(x,b))>0&&(x=t(x.length))}else x=r(w);return 0===d(x)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,m(s,0),r,i,0,n,{readonly:!0})}(y,c,n(x,b),v):(f=i(u,j,f,v,function(e,s,r,n){var t,i,d;for(t=e.data,i=[s,r,n],d=0;d\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MODULES //\n\nimport sub2ind from '@stdlib/ndarray-base-sub2ind';\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","vind2bind","args","i","push","start","sub2ind","apply","sliceStart","rdims","out","j","step","slice2strides"],"mappings":";;27BAgFA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EChFlD,CAENY,UAAY,IDuFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GElGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFwFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EAASyB,EAAWvB,EAAOH,EAASC,EAAQG,EGpG7C,SAAqBR,EAAOO,EAAOH,EAASC,GAC3C,IAAIc,EACAY,EACAC,EAIJ,IAFAb,EAAOnB,EAAMmB,KACbY,EAAO,CAAExB,EAAOH,EAASC,GACnB2B,EAAI,EAAGA,EAAIb,EAAKL,OAAQkB,IAC7BD,EAAKE,KAAMd,EAAMa,GAAIE,OAGtB,OADAH,EAAKE,KAAM,SACJE,EAAQC,MAAO,KAAML,EAC7B,CHwFoDM,CAAYxB,EAAIN,EAAOH,EAAS,GAAK,SAMrE,KAHnBQ,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECvH7C,CAENY,UAAY,KDwHbhB,EI9GD,SAAwBJ,EAAOI,EAASkC,GACvC,IAAInB,EACAoB,EACAP,EACAQ,EAIJ,IAFArB,EAAOnB,EAAMmB,KACboB,EAAM,GACAP,EAAI,EAAGA,EAAIM,EAAMxB,OAAQkB,IAC9BQ,EAAIF,EAAON,GACXO,EAAIN,KAAM7B,EAAQoC,GAAKrB,EAAKqB,GAAGC,MAEhC,OAAOF,CACR,CJiGWG,CAAe7B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC7H9C,CAENY,UAAY,KD4Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 891ae2e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0fbfefdfda519d276aeaa9dd7a6dbad6b5b8c4f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 26 Sep 2023 23:18:18 +0000 Subject: [PATCH 005/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 161 - lib/options.js | 39 - lib/slice_start.js | 59 - lib/slice_strides.js | 60 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 281 - 44 files changed, 6208 insertions(+), 5335 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html 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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 7ad6bb6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 9ef1395..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 df02b32..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var l=function(i,a){return function(){return a||i((a={exports:{}}).exports,a),a.exports}};var g=l(function(W,q){ -var M=require('@stdlib/ndarray-base-sub2ind/dist');function N(i,a,u,s){var e,r,t;for(e=i.data,r=[a,u,s],t=0;t0&&(n=K(n.length))}else n=A(o);return E(n)===0?Q(c,r,h(n,d),v):(e=L(t,s,e,v,O(o,t,s,0),"throw"),n=h(n,d),n.length===0?new c(r,i.data,[],[0],e,v,m()):(s=P(o,s,d),new c(r,i.data,n,s,e,v,m())))}k.exports=T -});var U=D();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 9e8c673..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,EAAU,QAAS,8BAA+B,EAmBtD,SAASC,EAAYC,EAAOC,EAAOC,EAASC,EAAS,CACpD,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOJ,EAAM,KACbK,EAAO,CAAEJ,EAAOC,EAASC,CAAO,EAC1BG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,EAAK,KAAMD,EAAME,CAAE,EAAE,KAAM,EAE5B,OAAAD,EAAK,KAAM,OAAQ,EACZP,EAAQ,MAAO,KAAMO,CAAK,CAClC,CAKAR,EAAO,QAAUE,IC1DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAY,QAAS,gCAAiC,EACtDC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQpB,EAAsBa,CAAE,EAGhCW,EAAKzB,EAAqBc,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKzB,EAAqBc,EAAGK,EAAO,EAAM,EAG1CK,EAAKtB,EAAYuB,CAAG,EAGfnB,EAAOH,EAAMqB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKpB,EAAOoB,EAAG,MAAO,EAExB,MAECA,EAAKtB,EAAYuB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOf,EAAMqB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAASZ,EAAWc,EAAOH,EAASC,EAAQG,EAAOZ,EAAYiB,EAAIN,EAAOH,EAAS,CAAE,EAAG,OAAQ,EAGhGQ,EAAKrB,EAAMqB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAX,EAAO,QAAUa,ICnGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sub2ind", "sliceStart", "slice", "shape", "strides", "offset", "data", "args", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "vind2bind", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..af94fe3 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function l(l,h,p){var j,f,c,u,v,b,g,y,x,w;if(c=l.dtype,u=l.shape,j=l.strides,f=l.offset,v=l.order,g=u.length,h.ndims!==g)throw new RangeError(a("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",u.join(","),h.ndims));if(y=l.constructor,0===g)return new y(c,l.data,u,j,f,v,{readonly:!0});if(b=s(h),(w=e(h,u,!0)).code){if(p)throw new RangeError(a("invalid argument. Slice exceeds array bounds. Array shape: (%s).",u.join(",")));w=e(h,u,!1),x=r(w),d(n(x,b))>0&&(x=t(x.length))}else x=r(w);return 0===d(x)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,m(s,0),r,i,0,n,{readonly:!0})}(y,c,n(x,b),v):(f=i(u,j,f,v,function(e,s,r,n){var t,i,d;for(t=e.data,i=[s,r,n],d=0;d\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MODULES //\n\nimport sub2ind from '@stdlib/ndarray-base-sub2ind';\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","vind2bind","args","i","push","start","sub2ind","apply","sliceStart","rdims","out","j","step","slice2strides"],"mappings":";;27BAgFA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EChFlD,CAENY,UAAY,IDuFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GElGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFwFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EAASyB,EAAWvB,EAAOH,EAASC,EAAQG,EGpG7C,SAAqBR,EAAOO,EAAOH,EAASC,GAC3C,IAAIc,EACAY,EACAC,EAIJ,IAFAb,EAAOnB,EAAMmB,KACbY,EAAO,CAAExB,EAAOH,EAASC,GACnB2B,EAAI,EAAGA,EAAIb,EAAKL,OAAQkB,IAC7BD,EAAKE,KAAMd,EAAMa,GAAIE,OAGtB,OADAH,EAAKE,KAAM,SACJE,EAAQC,MAAO,KAAML,EAC7B,CHwFoDM,CAAYxB,EAAIN,EAAOH,EAAS,GAAK,SAMrE,KAHnBQ,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECvH7C,CAENY,UAAY,KDwHbhB,EI9GD,SAAwBJ,EAAOI,EAASkC,GACvC,IAAInB,EACAoB,EACAP,EACAQ,EAIJ,IAFArB,EAAOnB,EAAMmB,KACboB,EAAM,GACAP,EAAI,EAAGA,EAAIM,EAAMxB,OAAQkB,IAC9BQ,EAAIF,EAAON,GACXO,EAAIN,KAAM7B,EAAQoC,GAAKrB,EAAKqB,GAAGC,MAEhC,OAAOF,CACR,CJiGWG,CAAe7B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC7H9C,CAENY,UAAY,KD4Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 2df283c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,161 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index cad2904..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); - - -// MAIN // - -/** -* Resolves the linear index of the first element indexed by a normalized multi-slice. -* -* ## Notes -* -* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - index offset -* @returns {NonNegativeInteger} linear index of the first element -*/ -function sliceStart( slice, shape, strides, offset ) { - var data; - var args; - var i; - - data = slice.data; - args = [ shape, strides, offset ]; - for ( i = 0; i < data.length; i++ ) { - args.push( data[ i ].start ); - } - args.push( 'throw' ); - return sub2ind.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index d619b40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-sub2ind": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..379c598 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index f3f2656..0000000 --- a/test/test.js +++ /dev/null @@ -1,281 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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(); -}); From d6ad1bae9890acce0b830140550f1a0a626c2d24 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:25:41 +0000 Subject: [PATCH 006/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4ed8246..bad08b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 83ceb5c..9670f40 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From b74bcc48876481d2832bc452003cab7b631a4451 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:26:10 +0000 Subject: [PATCH 007/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index af94fe3..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function l(l,h,p){var j,f,c,u,v,b,g,y,x,w;if(c=l.dtype,u=l.shape,j=l.strides,f=l.offset,v=l.order,g=u.length,h.ndims!==g)throw new RangeError(a("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",u.join(","),h.ndims));if(y=l.constructor,0===g)return new y(c,l.data,u,j,f,v,{readonly:!0});if(b=s(h),(w=e(h,u,!0)).code){if(p)throw new RangeError(a("invalid argument. Slice exceeds array bounds. Array shape: (%s).",u.join(",")));w=e(h,u,!1),x=r(w),d(n(x,b))>0&&(x=t(x.length))}else x=r(w);return 0===d(x)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,m(s,0),r,i,0,n,{readonly:!0})}(y,c,n(x,b),v):(f=i(u,j,f,v,function(e,s,r,n){var t,i,d;for(t=e.data,i=[s,r,n],d=0;d\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = vind2bind( shape, strides, offset, order, sliceStart( ns, shape, strides, 0 ), 'throw' ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MODULES //\n\nimport sub2ind from '@stdlib/ndarray-base-sub2ind';\n\n\n// MAIN //\n\n/**\n* Resolves the linear index of the first element indexed by a normalized multi-slice.\n*\n* ## Notes\n*\n* - If `strides` contains negative strides, if an `offset` is greater than `0`, the function returns a linear index with respect to the underlying data buffer. If an `offset` is equal to `0`, the function returns a linear index with respect to the array view. For more information, see `@stdlib/ndarray/base/sub2ind`.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - index offset\n* @returns {NonNegativeInteger} linear index of the first element\n*/\nfunction sliceStart( slice, shape, strides, offset ) {\n\tvar data;\n\tvar args;\n\tvar i;\n\n\tdata = slice.data;\n\targs = [ shape, strides, offset ];\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\targs.push( data[ i ].start );\n\t}\n\targs.push( 'throw' );\n\treturn sub2ind.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","vind2bind","args","i","push","start","sub2ind","apply","sliceStart","rdims","out","j","step","slice2strides"],"mappings":";;27BAgFA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EChFlD,CAENY,UAAY,IDuFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GElGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFwFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EAASyB,EAAWvB,EAAOH,EAASC,EAAQG,EGpG7C,SAAqBR,EAAOO,EAAOH,EAASC,GAC3C,IAAIc,EACAY,EACAC,EAIJ,IAFAb,EAAOnB,EAAMmB,KACbY,EAAO,CAAExB,EAAOH,EAASC,GACnB2B,EAAI,EAAGA,EAAIb,EAAKL,OAAQkB,IAC7BD,EAAKE,KAAMd,EAAMa,GAAIE,OAGtB,OADAH,EAAKE,KAAM,SACJE,EAAQC,MAAO,KAAML,EAC7B,CHwFoDM,CAAYxB,EAAIN,EAAOH,EAAS,GAAK,SAMrE,KAHnBQ,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECvH7C,CAENY,UAAY,KDwHbhB,EI9GD,SAAwBJ,EAAOI,EAASkC,GACvC,IAAInB,EACAoB,EACAP,EACAQ,EAIJ,IAFArB,EAAOnB,EAAMmB,KACboB,EAAM,GACAP,EAAI,EAAGA,EAAIM,EAAMxB,OAAQkB,IAC9BQ,EAAIF,EAAON,GACXO,EAAIN,KAAM7B,EAAQoC,GAAKrB,EAAKqB,GAAGC,MAEhC,OAAOF,CACR,CJiGWG,CAAe7B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC7H9C,CAENY,UAAY,KD4Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 379c598..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5b8cd2d19bad7830ddf03273e43ffac9c71f0b62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:27:54 +0000 Subject: [PATCH 008/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 160 - lib/options.js | 39 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 330 -- test/test.js | 330 -- 45 files changed, 6208 insertions(+), 5700 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 7ad6bb6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 9ef1395..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 169e14b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var f=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var g=f(function(T,q){ -function M(t,i,o){var a,e,r;for(a=t.data,e=o,r=0;r0&&(n=I(n.length))}else n=A(u);return E(n)===0?L(c,r,p(n,d),v):(e=J(u,a,e),n=p(n,d),n.length===0?new c(r,t.data,[],[0],e,v,h()):(a=K(u,a,d),new c(r,t.data,n,a,e,v,h())))}k.exports=O -});var P=D();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8bbded4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQnB,EAAsBY,CAAE,EAGhCW,EAAKxB,EAAqBa,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBa,EAAGK,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAV,EAAO,QAAUY,IClGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a678a2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 bad08b0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 9670f40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4588cae --- /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 1f59e25..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,330 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var slice = require( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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( 'the function returns a view of a provided input array (ndims=1)', 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, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, '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, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, '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' ); - } - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2f96669..0000000 --- a/test/test.js +++ /dev/null @@ -1,330 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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( 'the function returns a view of a provided input array (ndims=1)', 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, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, '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, true ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, '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' ); - } - t.end(); -}); From 4516467737b75223e01558427bd8fe3ed357de2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:40:01 +0000 Subject: [PATCH 009/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4ed8246..bad08b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 83ceb5c..9670f40 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 1ac5a8525941887377903886c895487cbcdd5c44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:40:28 +0000 Subject: [PATCH 010/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a678a2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4588cae..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8ae54ac43d88c39ea95d284eb84fc0842d0a7caa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 02:42:14 +0000 Subject: [PATCH 011/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 160 - lib/options.js | 39 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 377 -- test/test.js | 377 -- 45 files changed, 6208 insertions(+), 5794 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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' - uses: styfle/cancel-workflow-action@0.11.0 - 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 7ad6bb6..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS 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 the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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 9ef1395..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' - uses: actions/upload-artifact@v3 - 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' - uses: distributhor/workflow-webhook@v3 - 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - 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' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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' - uses: act10ns/slack@v2 - 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' - uses: actions/checkout@v3 - - # 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' - uses: actions/setup-node@v3 - 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 + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 169e14b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var f=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var g=f(function(T,q){ -function M(t,i,o){var a,e,r;for(a=t.data,e=o,r=0;r0&&(n=I(n.length))}else n=A(u);return E(n)===0?L(c,r,p(n,d),v):(e=J(u,a,e),n=p(n,d),n.length===0?new c(r,t.data,[],[0],e,v,h()):(a=K(u,a,d),new c(r,t.data,n,a,e,v,h())))}k.exports=O -});var P=D();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8bbded4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQnB,EAAsBY,CAAE,EAGhCW,EAAKxB,EAAqBa,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBa,EAAGK,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAV,EAAO,QAAUY,IClGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f33d226 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,b,g,v,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,b=c.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(g=o.constructor,0===b)return new g(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),v=r(y),i(n(v,u))>0&&(v=t(v.length))}else v=r(y);return 0===i(v)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(g,j,n(v,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wtBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 bad08b0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 9670f40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b9b07a6 --- /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 e3a4658..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,377 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 baseCtor = require( '@stdlib/ndarray-base-ctor' ); -var ctor = require( '@stdlib/ndarray-ctor' ); -var slice = require( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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( 'the function returns a view of a provided input array (ndims=1)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5287177..0000000 --- a/test/test.js +++ /dev/null @@ -1,377 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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( 'the function returns a view of a provided input array (ndims=1)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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(); -}); From c3d577c7a72f7e428dff8f6318ceccb464723d0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 07:53:43 +0000 Subject: [PATCH 012/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4ed8246..bad08b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 83ceb5c..9670f40 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From f32510bc6e54867faec69a0340a50b9831ca72ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 07:54:17 +0000 Subject: [PATCH 013/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f33d226..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,b,g,v,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,b=c.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(g=o.constructor,0===b)return new g(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),v=r(y),i(n(v,u))>0&&(v=t(v.length))}else v=r(y);return 0===i(v)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(g,j,n(v,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wtBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b9b07a6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f9c40a178ac00321d9a10864d0b2674a8869c0af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 07:56:04 +0000 Subject: [PATCH 014/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 160 - lib/options.js | 39 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 634 --- test/test.js | 634 --- 45 files changed, 6208 insertions(+), 6366 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 169e14b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var f=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var g=f(function(T,q){ -function M(t,i,o){var a,e,r;for(a=t.data,e=o,r=0;r0&&(n=I(n.length))}else n=A(u);return E(n)===0?L(c,r,p(n,d),v):(e=J(u,a,e),n=p(n,d),n.length===0?new c(r,t.data,[],[0],e,v,h()):(a=K(u,a,d),new c(r,t.data,n,a,e,v,h())))}k.exports=O -});var P=D();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8bbded4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQnB,EAAsBY,CAAE,EAGhCW,EAAKxB,EAAqBa,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBa,EAAGK,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAV,EAAO,QAAUY,IClGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a678a2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 bad08b0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 9670f40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4a98762 --- /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 b30b4b4..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,634 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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 = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s, true ); - - 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 = [ 6, 12, 18, 24 ]; - 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, true ); - - 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 = [ 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 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s, true ); - - 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 = [ 20, 8 ]; - 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, true ); - - 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 = [ 10, 12 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d69909..0000000 --- a/test/test.js +++ /dev/null @@ -1,634 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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 = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s, true ); - - 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 = [ 6, 12, 18, 24 ]; - 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, true ); - - 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 = [ 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 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s, true ); - - 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 = [ 20, 8 ]; - 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, true ); - - 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 = [ 10, 12 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7ef0062de910c9675096b23f5d38fa81e29bae79 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:17:41 +0000 Subject: [PATCH 015/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4ed8246..bad08b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 83ceb5c..9670f40 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 6d0b59d7916a480c05546b994f76917464a4328b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:18:18 +0000 Subject: [PATCH 016/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a678a2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4a98762..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6fd75abaf8a72887144dddb2fda1bc5ce1e0115d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:19:48 +0000 Subject: [PATCH 017/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 128 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 160 - lib/options.js | 39 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 852 --- test/test.js | 852 --- 45 files changed, 6208 insertions(+), 6802 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 169e14b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var f=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var g=f(function(T,q){ -function M(t,i,o){var a,e,r;for(a=t.data,e=o,r=0;r0&&(n=I(n.length))}else n=A(u);return E(n)===0?L(c,r,p(n,d),v):(e=J(u,a,e),n=p(n,d),n.length===0?new c(r,t.data,[],[0],e,v,h()):(a=K(u,a,d),new c(r,t.data,n,a,e,v,h())))}k.exports=O -});var P=D();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8bbded4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQnB,EAAsBY,CAAE,EAGhCW,EAAKxB,EAAqBa,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBa,EAAGK,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAV,EAAO,QAAUY,IClGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 b630122..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a678a2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 bad08b0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 9670f40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a53f178 --- /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 aef430d..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,852 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6345676..0000000 --- a/test/test.js +++ /dev/null @@ -1,852 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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 5afa8cdf08a1cd07eaaa615832dab680e3ea0f63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:35:45 +0000 Subject: [PATCH 018/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4ed8246..bad08b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var options = require( './options.js' ); diff --git a/package.json b/package.json index 83ceb5c..9670f40 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 9d2d08cd9a0caad474dea34e5d0c558da0966e3f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:36:18 +0000 Subject: [PATCH 019/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a678a2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a53f178..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c419fa64f1f6016a2e12035a848eab27ddb11a2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 27 Sep 2023 08:37:32 +0000 Subject: [PATCH 020/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 13 - dist/index.js.map | 7 - docs/repl.txt | 38 - docs/types/test.ts | 127 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 56 - lib/index.js | 67 - lib/main.js | 160 - lib/options.js | 39 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 852 --- test/test.js | 852 --- 45 files changed, 6208 insertions(+), 6801 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/options.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -234,7 +227,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -294,7 +287,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 2b1ef2a..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false ); - if ( typeof v !== 'object' ) { - b.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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 169e14b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict";var f=function(t,i){return function(){return i||t((i={exports:{}}).exports,i),i.exports}};var g=f(function(T,q){ -function M(t,i,o){var a,e,r;for(a=t.data,e=o,r=0;r0&&(n=I(n.length))}else n=A(u);return E(n)===0?L(c,r,p(n,d),v):(e=J(u,a,e),n=p(n,d),n.length===0?new c(r,t.data,[],[0],e,v,h()):(a=K(u,a,d),new c(r,t.data,n,a,e,v,h())))}k.exports=O -});var P=D();module.exports=P; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 8bbded4..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/options.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nmodule.exports = options;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar options = require( './options.js' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar options = require( './options.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a read-only view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\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-base-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-base-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, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA4BA,SAASC,GAAU,CAClB,MAAO,CAEN,SAAY,EACb,CACD,CAKAD,EAAO,QAAUC,ICtCjB,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAU,IAed,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACAC,EAEJ,OAAAA,EAAQH,EAAM,OACTG,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIL,EAAMC,EAAOL,EAAQK,EAAO,CAAE,EAAGC,EAAOE,EAAS,EAAGD,EAAOL,EAAQ,CAAE,CACjF,CAKAH,EAAO,QAAUI,ICvDjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAU,IACVC,EAAQ,IA+CZ,SAASC,EAAOC,EAAGC,EAAGC,EAAS,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAE,MACVM,EAAQN,EAAE,MACVG,EAAUH,EAAE,QACZI,EAASJ,EAAE,OACXO,EAAQP,EAAE,MACVS,EAAQH,EAAM,OAGTL,EAAE,QAAUQ,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGL,EAAE,KAAM,CAAE,EAMpM,GAHAS,EAAOV,EAAE,YAGJS,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOL,EAAE,KAAMM,EAAOH,EAASC,EAAQG,EAAOV,EAAQ,CAAE,EAS1E,GANAW,EAAQnB,EAAsBY,CAAE,EAGhCW,EAAKxB,EAAqBa,EAAGK,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKV,EACJ,MAAM,IAAI,WAAYR,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBa,EAAGK,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbb,EAAOY,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,CAAM,GAGrDH,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOL,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGI,EAAQG,EAAOV,EAAQ,CAAE,GAGrEM,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOL,EAAE,KAAMW,EAAIR,EAASC,EAAQG,EAAOV,EAAQ,CAAE,GACvE,CAKAV,EAAO,QAAUY,IClGjB,IAAIc,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_options", "__commonJSMin", "exports", "module", "options", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "options", "empty", "ctor", "dtype", "shape", "order", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "options", "empty", "slice", "x", "s", "strict", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 1ec9377..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,38 +0,0 @@ - -{{alias}}( x, slice, strict ) - Returns a read-only view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - 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, false ) - - > 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 bda21d5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s, false ); // $ExpectError - slice( 10, s, false ); // $ExpectError - slice( false, s, false ); // $ExpectError - slice( true, s, false ); // $ExpectError - slice( null, s, false ); // $ExpectError - slice( [], s, false ); // $ExpectError - slice( {}, s, false ); // $ExpectError - slice( ( x: number ): number => x, s, false ); // $ExpectError - - slice( '10', s, true ); // $ExpectError - slice( 10, s, true ); // $ExpectError - slice( false, s, true ); // $ExpectError - slice( true, s, true ); // $ExpectError - slice( null, s, true ); // $ExpectError - slice( [], s, true ); // $ExpectError - slice( {}, s, true ); // $ExpectError - slice( ( x: number ): number => x, s, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false ); // $ExpectError - slice( x, 5, false ); // $ExpectError - slice( x, false, false ); // $ExpectError - slice( x, true, false ); // $ExpectError - slice( x, null, false ); // $ExpectError - slice( x, undefined, false ); // $ExpectError - slice( x, [ '5' ], false ); // $ExpectError - slice( x, {}, false ); // $ExpectError - slice( x, ( x: number ): number => x, false ); // $ExpectError - - slice( x, '5', true ); // $ExpectError - slice( x, 5, true ); // $ExpectError - slice( x, false, true ); // $ExpectError - slice( x, true, true ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, undefined, true ); // $ExpectError - slice( x, [ '5' ], true ); // $ExpectError - slice( x, {}, true ); // $ExpectError - slice( x, ( x: number ): number => x, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - 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, null ); // $ExpectError - slice( x, s, undefined ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, s, {} ); // $ExpectError - slice( x, s, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index fe7add8..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false ); -// 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, false ); -// 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, false ); -// 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, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false ); -// 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, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 2e1b191..bcf29c0 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3a678a2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index f0e674c..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var options = require( './options.js' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c0f5ff0..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-base-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-base-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, false ); -* // 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 bad08b0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,160 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var options = require( './options.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @throws {RangeError} number of slice dimensions must match the number of array dimensions -* @throws {RangeError} slice exceeds array bounds -* @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, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, options() ); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, options() ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/options.js b/lib/options.js deleted file mode 100644 index 6456451..0000000 --- a/lib/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns array creation options. -* -* @private -* @returns {Object} options -*/ -function options() { - return { - // Default to always returning read-only arrays: - 'readonly': true - }; -} - - -// EXPORTS // - -module.exports = options; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 9670f40..bda99cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.0", - "@stdlib/ndarray-base-buffer": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "github:stdlib-js/slice-base-nonreduced-dimensions#main", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e7f9d31 --- /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 aef430d..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,852 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 6345676..0000000 --- a/test/test.js +++ /dev/null @@ -1,852 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true ); - }; - } -}); - -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, 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 ], 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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, true ); - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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)', 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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, true ); - - 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 d50f9c759bdf04c1a565b7dd0a8a290f2d75365b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:48:45 +0000 Subject: [PATCH 021/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 4cb7e32..2094e71 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 76a39a9..4591327 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 1562a4cebbcffe2d4154bbe3d3cf242cf8db5642 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:49:19 +0000 Subject: [PATCH 022/143] Remove files --- index.d.ts | 576 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6758 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 bcf29c0..0000000 --- a/index.d.ts +++ /dev/null @@ -1,576 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, slice: MultiSlice, strict: boolean ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, slice: MultiSlice, strict: boolean ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, slice: MultiSlice, strict: boolean ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, slice: MultiSlice, strict: boolean ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, slice: MultiSlice, strict: boolean ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, slice: MultiSlice, strict: boolean ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, slice: MultiSlice, strict: boolean ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, slice: MultiSlice, strict: boolean ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, slice: MultiSlice, strict: boolean ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, slice: MultiSlice, strict: boolean ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, slice: MultiSlice, strict: boolean ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, slice: MultiSlice, strict: boolean ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var 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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, slice: MultiSlice, strict: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a678a2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.0-esm/index.mjs";function o(o,m,l){var h,f,j,c,p,u,v,b,g,y;if(j=o.dtype,c=o.shape,h=o.strides,f=o.offset,p=o.order,v=c.length,m.ndims!==v)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",c.join(","),m.ndims));if(b=o.constructor,0===v)return new b(j,o.data,c,h,f,p,{readonly:!0});if(u=s(m),(y=e(m,c,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",c.join(",")));y=e(m,c,!1),g=r(y),i(n(g,u))>0&&(g=t(g.length))}else g=r(y);return 0===i(g)?function(e,s,r,n){var i,d;return i=0===(d=r.length)?[0]:t(d),new e(s,a(s,0),r,i,0,n,{readonly:!0})}(b,j,n(g,u),p):(f=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false );\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, strict ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, options() ); // eslint-disable-line max-len\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, options() );\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, options() );\n}\n\n\n// EXPORTS //\n\nexport default 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// MAIN //\n\n/**\n* Returns array creation options.\n*\n* @private\n* @returns {Object} options\n*/\nfunction options() {\n\treturn {\n\t\t// Default to always returning read-only arrays:\n\t\t'readonly': true\n\t};\n}\n\n\n// EXPORTS //\n\nexport default options;\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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\nimport options from './options.js';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, options() ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;2vBA+EA,SAASA,EAAOC,EAAGC,EAAGC,GACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQL,EAAEK,MACVC,EAAQN,EAAEM,MACVH,EAAUH,EAAEG,QACZC,EAASJ,EAAEI,OACXG,EAAQP,EAAEO,MACVE,EAAQH,EAAMO,OAGTZ,EAAEQ,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOf,EAAEQ,QAM5L,GAHAC,EAAOV,EAAEiB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAOL,EAAEkB,KAAMZ,EAAOH,EAASC,EAAQG,EC/ElD,CAENY,UAAY,IDsFb,GANAX,EAAQY,EAAsBnB,IAG9BW,EAAKS,EAAqBpB,EAAGK,GAAO,IAG5BgB,KAAO,CACd,GAAKpB,EACJ,MAAM,IAAIY,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBpB,EAAGK,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GEjGb,SAAgBD,EAAML,EAAOC,EAAOC,GACnC,IAAIJ,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EDpBxD,CAENY,UAAY,GCmBd,CFuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,IAG/CH,EG7GD,SAAqBL,EAAOI,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOnB,EAAMmB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CHkGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAOL,EAAEkB,KAAM,GAAI,CAAE,GAAKd,EAAQG,ECtH7C,CAENY,UAAY,KDuHbhB,EI7GD,SAAwBJ,EAAOI,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOnB,EAAMmB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CJgGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOL,EAAEkB,KAAMP,EAAIR,EAASC,EAAQG,EC5H9C,CAENY,UAAY,KD2Hd"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e7f9d31..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d8e9db73ef7d41529bb5dd12117d75fd4ce172af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:50:54 +0000 Subject: [PATCH 023/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 41 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 166 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 998 ---- test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 7078 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -235,7 +228,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -295,7 +288,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 6531d26..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var q=f(function(O,p){ -function k(e,a,o){var t,i,r;for(t=e.data,i=o,r=0;r0&&(n=F(n.length))}else n=z(d);return A(n)===0?I(l,s,m(n,c),v,!t):(r=G(d,i,r),n=m(n,c),n.length===0?new l(s,e.data,[],[0],r,v,{readonly:!t}):(i=H(d,i,c),new l(s,e.data,n,i,r,v,{readonly:!t})))}R.exports=J -});var K=b();module.exports=K; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d85030e..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} mutable - boolean indicating whether a returned array should be mutable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, mutable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !mutable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !mutable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAU,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAE,MACVO,EAAQP,EAAE,MACVI,EAAUJ,EAAE,QACZK,EAASL,EAAE,OACXQ,EAAQR,EAAE,MACVU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAON,EAAE,KAAMO,EAAOH,EAASC,EAAQG,EAAO,CAC9D,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQnB,EAAsBW,CAAE,EAGhCY,EAAKxB,EAAqBY,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBY,EAAGM,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAQ,GAG/DE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAON,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CACzD,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAON,EAAE,KAAMY,EAAIR,EAASC,EAAQG,EAAO,CAC3D,SAAY,CAACL,CACd,CAAC,GACF,CAKAf,EAAO,QAAUW,ICxGjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "mutable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 4973957..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,41 +0,0 @@ - -{{alias}}( x, slice, strict, mutable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - mutable: boolean - Boolean indicating whether a returned array should be mutable. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 f472861..38751fd 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2ddee16 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, mutable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !mutable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !mutable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","mutable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 2094e71..0000000 --- a/lib/main.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} mutable - boolean indicating whether a returned array should be mutable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, mutable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, { - 'readonly': !mutable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !mutable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, { - 'readonly': !mutable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, { - 'readonly': !mutable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4591327..5452b06 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a 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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..72cfb22 --- /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 a821fef..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, mutable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, mutable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, mutable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 35949c7..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, mutable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, mutable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, mutable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 65baa9fe657bf582d39a8c453ccdf468fe23ea42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:51:52 +0000 Subject: [PATCH 024/143] Update README.md for ESM bundle v0.0.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f5329a7..96eba2d 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs'; ``` #### slice( x, slice, strict, mutable ) @@ -134,7 +134,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 836f7c9b3d33228a585401f6e385aaef9c2a30a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 02:51:53 +0000 Subject: [PATCH 025/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96eba2d..443e0c3 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.0.0-esm/index.mjs'; ``` @@ -134,7 +139,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-base-slice@v0.0.0-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 8c4fb8e2e559ea288852b79e7e2b39a0817cfdb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:45:00 +0000 Subject: [PATCH 026/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index da7edfe..9e6450d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 76a39a9..4591327 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From b034214476314db91c7c30704e19dd17b0a1d2f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:50:41 +0000 Subject: [PATCH 027/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 38751fd..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, mutable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, mutable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, mutable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, mutable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, mutable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param mutable - boolean indicating whether a returned array should be mutable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, mutable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2ddee16..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, mutable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !mutable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !mutable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !mutable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","mutable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 72cfb22..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f33af543c33f769b25b1f1c8b27591495df62662 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 30 Sep 2023 10:52:30 +0000 Subject: [PATCH 028/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 166 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 998 ---- test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 7080 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 acad615..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var q=f(function(O,p){ -function k(e,a,o){var i,t,r;for(i=e.data,t=o,r=0;r0&&(n=F(n.length))}else n=z(d);return A(n)===0?I(l,s,h(n,c),v,!i):(r=G(d,t,r),n=h(n,c),n.length===0?new l(s,e.data,[],[0],r,v,{readonly:!i}):(t=H(d,t,c),new l(s,e.data,n,t,r,v,{readonly:!i})))}R.exports=J -});var K=b();module.exports=K; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c2c375b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAE,MACVO,EAAQP,EAAE,MACVI,EAAUJ,EAAE,QACZK,EAASL,EAAE,OACXQ,EAAQR,EAAE,MACVU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAON,EAAE,KAAMO,EAAOH,EAASC,EAAQG,EAAO,CAC9D,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQnB,EAAsBW,CAAE,EAGhCY,EAAKxB,EAAqBY,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBY,EAAGM,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAON,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CACzD,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAON,EAAE,KAAMY,EAAIR,EAASC,EAAQG,EAAO,CAC3D,SAAY,CAACL,CACd,CAAC,GACF,CAKAf,EAAO,QAAUW,ICxGjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 28d1e85..6b89b71 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2ddee16 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 9e6450d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4591327..5452b06 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a 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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5fc250c --- /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 a9e24ca..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 0175e95ddcbe0c22422ad05c8c704fb3f57ae3e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 16:31:29 +0000 Subject: [PATCH 029/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index da7edfe..9e6450d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 76a39a9..4591327 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d5d2f277c626fcb398164c1f6966458a3d2c7eba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 01:31:38 +0000 Subject: [PATCH 030/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 6b89b71..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2ddee16..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5fc250c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4d15a7d135d84aa9512f8571e6a9e2387a33eda5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 01:33:06 +0000 Subject: [PATCH 031/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 166 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 998 ---- test/test.js | 998 ---- 45 files changed, 6208 insertions(+), 7081 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ae64e3b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:16:29.460Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 acad615..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var q=f(function(O,p){ -function k(e,a,o){var i,t,r;for(i=e.data,t=o,r=0;r0&&(n=F(n.length))}else n=z(d);return A(n)===0?I(l,s,h(n,c),v,!i):(r=G(d,t,r),n=h(n,c),n.length===0?new l(s,e.data,[],[0],r,v,{readonly:!i}):(t=H(d,t,c),new l(s,e.data,n,t,r,v,{readonly:!i})))}R.exports=J -});var K=b();module.exports=K; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c2c375b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAE,MACVO,EAAQP,EAAE,MACVI,EAAUJ,EAAE,QACZK,EAASL,EAAE,OACXQ,EAAQR,EAAE,MACVU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAON,EAAE,KAAMO,EAAOH,EAASC,EAAQG,EAAO,CAC9D,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQnB,EAAsBW,CAAE,EAGhCY,EAAKxB,EAAqBY,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBY,EAAGM,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAON,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CACzD,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAON,EAAE,KAAMY,EAAIR,EAASC,EAAQG,EAAO,CAC3D,SAAY,CAACL,CACd,CAAC,GACF,CAKAf,EAAO,QAAUW,ICxGjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 28d1e85..6b89b71 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2ddee16 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 9e6450d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4591327..5452b06 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a 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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.0", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.0", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3b452b0 --- /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 a9e24ca..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 4e5325a9b7f2a5c694a380d4f991ee082a7bd395 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 19:38:35 +0000 Subject: [PATCH 032/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index da7edfe..9e6450d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -26,7 +26,7 @@ var sliceShape = require( '@stdlib/slice-base-shape' ); var take = require( '@stdlib/array-base-take' ); var zeros = require( '@stdlib/array-base-zeros' ); var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 1142361..0cf5853 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From eb40db744fbdf89cf53506511f30677092a7638a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:46:04 +0000 Subject: [PATCH 033/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 6b89b71..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2ddee16..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3b452b0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a317624cc593b902a454f0e608fa7e608fac84d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 02:47:40 +0000 Subject: [PATCH 034/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 166 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 73 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 998 ---- test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 7080 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 9990b43..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var q=f(function(O,p){ -function k(e,a,o){var i,t,r;for(i=e.data,t=o,r=0;r0&&(n=F(n.length))}else n=z(d);return A(n)===0?I(l,s,h(n,c),v,!i):(r=G(d,t,r),n=h(n,c),n.length===0?new l(s,e.data,[],[0],r,v,{readonly:!i}):(t=H(d,t,c),new l(s,e.data,n,t,r,v,{readonly:!i})))}R.exports=J -});var K=b();module.exports=K; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index c2c375b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAE,MACVO,EAAQP,EAAE,MACVI,EAAUJ,EAAE,QACZK,EAASL,EAAE,OACXQ,EAAQR,EAAE,MACVU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAON,EAAE,KAAMO,EAAOH,EAASC,EAAQG,EAAO,CAC9D,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQnB,EAAsBW,CAAE,EAGhCY,EAAKxB,EAAqBY,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAKxB,EAAqBY,EAAGM,EAAO,EAAM,EAG1CK,EAAKrB,EAAYsB,CAAG,EAGfnB,EAAOF,EAAMoB,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKnB,EAAOmB,EAAG,MAAO,EAExB,MAECA,EAAKrB,EAAYsB,CAAG,EAGrB,OAAKnB,EAAOkB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOd,EAAMoB,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAKpB,EAAMoB,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAON,EAAE,KAAM,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CACzD,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAON,EAAE,KAAMY,EAAIR,EAASC,EAAQG,EAAO,CAC3D,SAAY,CAACL,CACd,CAAC,GACF,CAKAf,EAAO,QAAUW,ICxGjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 28d1e85..6b89b71 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2a4828c --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 9e6450d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,166 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = x.dtype; - shape = x.shape; - strides = x.strides; - offset = x.offset; - order = x.order; - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, x.data, shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, x.data, [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, x.data, sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 0cf5853..5452b06 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a 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,52 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d9f5992 --- /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 a9e24ca..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 53e6967796889d4b15cbaca3c4bfcfbff2c84c03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:27:09 +0000 Subject: [PATCH 035/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a022a3f..834487d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From e8dc1feed147aed1c6845caa1bf506081212ce2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:31:25 +0000 Subject: [PATCH 036/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 6b89b71..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 2a4828c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function o(o,m,l,h){var f,j,c,p,u,v,b,g,y,x;if(c=o.dtype,p=o.shape,f=o.strides,j=o.offset,u=o.order,b=p.length,m.ndims!==b)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",p.join(","),m.ndims));if(g=o.constructor,0===b)return new g(c,o.data,p,f,j,u,{readonly:!h});if(v=s(m),(x=e(m,p,!0)).code){if(l)throw new RangeError(d("invalid argument. Slice exceeds array bounds. Array shape: (%s).",p.join(",")));x=e(m,p,!1),y=r(x),i(n(y,v))>0&&(y=t(y.length))}else y=r(x);return 0===i(y)?function(e,s,r,n,i){var d,o;return d=0===(o=r.length)?[0]:t(o),new e(s,a(s,0),r,d,0,n,{readonly:i})}(g,c,n(y,v),u,!h):(j=function(e,s,r){var n,t,i;for(n=e.data,t=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = x.dtype;\n\tshape = x.shape;\n\tstrides = x.strides;\n\toffset = x.offset;\n\torder = x.order;\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, x.data, shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, x.data, [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, x.data, sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","length","RangeError","format","join","constructor","data","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;kwBA+EA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQN,EAAEM,MACVC,EAAQP,EAAEO,MACVH,EAAUJ,EAAEI,QACZC,EAASL,EAAEK,OACXG,EAAQR,EAAEQ,MACVE,EAAQH,EAAMO,OAGTb,EAAES,QAAUA,EAChB,MAAM,IAAIK,WAAYC,EAAQ,uIAAwIT,EAAMU,KAAM,KAAOhB,EAAES,QAM5L,GAHAC,EAAOX,EAAEkB,YAGM,IAAVR,EACJ,OAAO,IAAIC,EAAML,EAAON,EAAEmB,KAAMZ,EAAOH,EAASC,EAAQG,EAAO,CAC9DY,UAAajB,IAUf,GANAM,EAAQY,EAAsBpB,IAG9BY,EAAKS,EAAqBrB,EAAGM,GAAO,IAG5BgB,KAAO,CACd,GAAKrB,EACJ,MAAM,IAAIa,WAAYC,EAAQ,mEAAoET,EAAMU,KAAM,OAG/GJ,EAAKS,EAAqBrB,EAAGM,GAAO,GAGpCK,EAAKY,EAAYX,GAGZY,EAAOC,EAAMd,EAAIH,IAAY,IACjCG,EAAKe,EAAOf,EAAGE,QAElB,MAEEF,EAAKY,EAAYX,GAGlB,OAAqB,IAAhBY,EAAOb,GCnGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOY,GAC1C,IAAIhB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMO,QAEH,CAAE,GAEFa,EAAOjB,GAEX,IAAIC,EAAML,EAAOsB,EAAQtB,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEY,SAAYA,GAEd,CDuFSS,CAAOlB,EAAML,EAAOoB,EAAMd,EAAIH,GAASD,GAAQL,IAGvDE,EE/GD,SAAqBN,EAAOK,EAASC,GACpC,IAAIc,EACAW,EACAC,EAIJ,IAFAZ,EAAOpB,EAAMoB,KACbW,EAAMzB,EACA0B,EAAI,EAAGA,EAAIZ,EAAKL,OAAQiB,IAC7BD,GAAO1B,EAAS2B,GAAMZ,EAAMY,GAAIC,MAEjC,OAAOF,CACR,CFoGUG,CAAYpB,EAAIT,EAASC,GAMf,KAHnBO,EAAKc,EAAMd,EAAIH,IAGPK,OACA,IAAIH,EAAML,EAAON,EAAEmB,KAAM,GAAI,CAAE,GAAKd,EAAQG,EAAO,CACzDY,UAAajB,KAIfC,EGjHD,SAAwBL,EAAOK,EAAS8B,GACvC,IAAIf,EACAgB,EACAJ,EACAK,EAIJ,IAFAjB,EAAOpB,EAAMoB,KACbgB,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMpB,OAAQiB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMjC,EAAQgC,GAAKjB,EAAKiB,GAAGE,MAEhC,OAAOH,CACR,CHoGWI,CAAe1B,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAON,EAAEmB,KAAMP,EAAIR,EAASC,EAAQG,EAAO,CAC3DY,UAAajB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d9f5992..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ec4ebb9489d52a74eefc39e1d837eb4634d1f997 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Oct 2023 20:32:59 +0000 Subject: [PATCH 037/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 998 ---- test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 7092 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 5d2177d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 345ca18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 28d1e85..6b89b71 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8c61e98 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,b,c,v){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,b.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),b.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!v});if(z=s(b),(S=e(b,x,!0)).code){if(c)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(b,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!v):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;swCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 cd24e6c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 834487d..5452b06 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "github:stdlib-js/ndarray-base-data-buffer#main", - "@stdlib/ndarray-base-dtype": "github:stdlib-js/ndarray-base-dtype#main", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "github:stdlib-js/ndarray-base-offset#main", - "@stdlib/ndarray-base-order": "github:stdlib-js/ndarray-base-order#main", - "@stdlib/ndarray-base-shape": "github:stdlib-js/ndarray-base-shape#main", - "@stdlib/ndarray-base-strides": "github:stdlib-js/ndarray-base-strides#main", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..73a820c --- /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 a9e24ca..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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( './../../dist' ); - - -// 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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 ba930086b5763e6874a20f53eab8c205ab8f1a9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:09:37 +0000 Subject: [PATCH 038/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75dd1dd..8c2d57a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From bee463691773ea7e17e45d2598bc28495b5a779d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:10:05 +0000 Subject: [PATCH 039/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 6b89b71..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8c61e98..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,b,c,v){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,b.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),b.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!v});if(z=s(b),(S=e(b,x,!0)).code){if(c)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(b,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!v):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;swCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 73a820c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3fddf6f765713ed290ff817aa5b0ff40a00deb6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:11:45 +0000 Subject: [PATCH 040/143] 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 | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 5d2177d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 345ca18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 28d1e85..6b89b71 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4a4280e --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;gzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 cd24e6c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 8c2d57a..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..640778b --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 5a251c7e8d7d5aaa19d187f97b94b8189962c21f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:12:17 +0000 Subject: [PATCH 041/143] 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 48a7c5e..19d56f6 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs'; ``` #### slice( x, slice, strict, writable ) @@ -138,7 +138,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 8652cbaffba7410b295a67180d61a4e4993117a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:12:18 +0000 Subject: [PATCH 042/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19d56f6..cf606fa 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs'; ``` @@ -138,7 +143,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-base-slice@v0.1.0-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From dc5dd877814098f6af8cff0990297a145d639550 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:27:22 +0000 Subject: [PATCH 043/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 75dd1dd..8c2d57a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 2180a730737c74ef7418922eb020699a2e05623b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:32:51 +0000 Subject: [PATCH 044/143] Remove files --- index.d.ts | 589 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6771 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 6b89b71..0000000 --- a/index.d.ts +++ /dev/null @@ -1,589 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4a4280e..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;gzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 640778b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cae1252d56db35eb3675592629c212534be4d1d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:34:21 +0000 Subject: [PATCH 045/143] 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 | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 5d2177d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 345ca18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4a4280e --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;gzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 cd24e6c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 8c2d57a..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4978a44 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 72b1ac3f13d6a326f7a3510cf21de9e29ae16e4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 17:17:31 +0000 Subject: [PATCH 046/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index cd24e6c..61762e5 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 75dd1dd..8c2d57a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 173c70adc4a3e038359b78f8d6554619e38c6ca7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:35:58 +0000 Subject: [PATCH 047/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4a4280e..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;gzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4978a44..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9fb3404166d84b3a6fcddd895f91a8f0b0e8fca1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 01:37:28 +0000 Subject: [PATCH 048/143] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 45 files changed, 6208 insertions(+), 6136 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 457169b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:34:44.253Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 5d2177d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 345ca18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c980bd2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;yzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 61762e5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 8c2d57a..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..42081c4 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 9ae8ef853ef671eb21a5f2dab2a456875445b740 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 11:25:54 +0000 Subject: [PATCH 049/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index cd24e6c..61762e5 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 0226e04..0bf045f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From b8fd7e0dee63d15ea4c54132af476d77de940d66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:56:15 +0000 Subject: [PATCH 050/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c980bd2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;yzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 42081c4..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 724e498ac94a888df015faf79379813a87875b6f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 14:57:41 +0000 Subject: [PATCH 051/143] 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 | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 5d2177d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 345ca18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,yBAA0B,EAC1CC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c980bd2 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;yzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 61762e5..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 0bf045f..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0f8f579 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 555908cca25394a9ccf4f66185356b24d8941c8f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 23 Nov 2023 09:54:04 +0000 Subject: [PATCH 052/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..84ed214 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index e366d53..b005314 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From acce4ad55f22284f20e80348aed0f7506fc86414 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 23 Nov 2023 09:58:16 +0000 Subject: [PATCH 053/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c980bd2..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;yzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0f8f579..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 92f88e9faa61d469b1b7dc71ed297b6c204238ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 23 Nov 2023 09:59:45 +0000 Subject: [PATCH 054/143] 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 | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 44 files changed, 6208 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e0f7906 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;0zCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 84ed214..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index b005314..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "github:stdlib-js/array-base-take-indexed#main", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.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.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a73d09a --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 a94d2d71f4c0a1ba486fdddf3e7ccee5ba208afb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 13:26:01 +0000 Subject: [PATCH 055/143] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..84ed214 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); diff --git a/package.json b/package.json index 8e46c14..6c5ce99 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 261cebc4d3a8e9977ed3f5d1f1e1ec904a9f4464 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:24:57 +0000 Subject: [PATCH 056/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e0f7906..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;0zCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a73d09a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 57af33e2785b553b5b48488dd0147b05508096a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 11:25:54 +0000 Subject: [PATCH 057/143] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 53 +- benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 45 files changed, 6208 insertions(+), 6131 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 390d9fb..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:39:37.760Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 0548e11..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0b60081 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 84ed214..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 6c5ce99..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.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.1.0", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fd4efc2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 9d67500d93cef5ec6ebe86e7c8afe024861919fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 07:59:55 +0000 Subject: [PATCH 058/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b17d59..4deee78 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 67ade8e1566e452108d78b8aff71ffa12257bdd4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:36:16 +0000 Subject: [PATCH 059/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0b60081..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=i(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),d(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===d(R)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fd4efc2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e9dd81258c2c655ad509be31f27240ff22ed9a50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:36:56 +0000 Subject: [PATCH 060/143] 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 | 53 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 46 files changed, 6208 insertions(+), 6137 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 6bcb202..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:08:58.642Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 37cfff8..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -239,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -299,7 +292,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 084644b..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 b9e2332..2977d8e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..90036b7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 216c524..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4deee78..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d554548 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 6cea37833d44d07156f85c383543fb2cbf882ef3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:31:57 +0000 Subject: [PATCH 061/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b17d59..4deee78 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", "@stdlib/slice-base-shape": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From a56c0142e944a2c08accb22b3cdbbabceb9469b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:58:02 +0000 Subject: [PATCH 062/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 2977d8e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 90036b7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d554548..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 617e48c62d07aea35c726288468ee8f0ed46a9d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:58:42 +0000 Subject: [PATCH 063/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 46 files changed, 6208 insertions(+), 6142 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 2243705..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:58:37.950Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 37cfff8..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..90036b7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 216c524..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4deee78..bbaaa2b 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.1.0", - "@stdlib/array-base-zeros": "^0.1.1", - "@stdlib/ndarray-base-buffer": "^0.1.1", - "@stdlib/ndarray-base-data-buffer": "^0.1.0", - "@stdlib/ndarray-base-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-offset": "^0.1.0", - "@stdlib/ndarray-base-order": "^0.1.0", - "@stdlib/ndarray-base-shape": "^0.1.0", - "@stdlib/ndarray-base-strides": "^0.1.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.1.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.1.0", - "@stdlib/slice-base-shape": "^0.1.1", - "@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/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..eb0959c --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 a7479c7f0838a84f6940b80cdee337083674053a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:11:40 +0000 Subject: [PATCH 064/143] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 00a1666..bf2fe4e 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.0", "@stdlib/slice-base-normalize-multi-slice": "^0.2.0", "@stdlib/slice-base-shape": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From c3d38beacfe049fb04401e3f794231c0286e41b0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:08:26 +0000 Subject: [PATCH 065/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 90036b7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index eb0959c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9e229dba8acdc4214d551e168bf76ef0c89dba1d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:09:29 +0000 Subject: [PATCH 066/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 45 files changed, 6208 insertions(+), 6145 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 beada65..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..53bdff2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 216c524..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index bf2fe4e..fb0e583 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Return a 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,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.0", - "@stdlib/array-base-zeros": "^0.2.0", - "@stdlib/ndarray-base-buffer": "^0.2.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.0", - "@stdlib/ndarray-base-dtype": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-offset": "^0.2.0", - "@stdlib/ndarray-base-order": "^0.2.0", - "@stdlib/ndarray-base-shape": "^0.2.0", - "@stdlib/ndarray-base-strides": "^0.2.0", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.0", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.0", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.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", - "@stdlib/slice-multi": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e63cf96 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 732d2e6f159996e0a11350436d31fe3b591a391d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:51:52 +0000 Subject: [PATCH 067/143] 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 738cafe..1d3c9b8 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs'; ``` #### slice( x, slice, strict, writable ) @@ -138,7 +138,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 4b77fc7b37a1b7781b9ba39407d90a97ccc36f66 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:51:53 +0000 Subject: [PATCH 068/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d3c9b8..f793556 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs'; ``` @@ -138,7 +143,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-base-slice@v0.2.0-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 842d3143e37472839a09b1102c98f4b53d5f9d51 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:06:08 +0000 Subject: [PATCH 069/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 99ebd53..804aaac 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 782c4b2eb9ce7824d1471983c07cb4393feda3b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:53:00 +0000 Subject: [PATCH 070/143] Remove files --- index.d.ts | 587 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6769 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 53bdff2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";function f(f,v,b,c){var g,u,y,x,w,z,A,E,R,S;if(y=d(f),x=m(f,!0),g=a(f,!0),u=o(f),w=l(f),A=x.length,v.ndims!==A)throw new RangeError(h("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",x.join(","),v.ndims));if(E=f.constructor,0===A)return new E(y,j(f),x,g,u,w,{readonly:!c});if(z=s(v),(S=e(v,x,!0)).code){if(b)throw new RangeError(h("invalid argument. Slice exceeds array bounds. Array shape: (%s).",x.join(",")));S=e(v,x,!1),R=r(S),i(t(R,z))>0&&(R=n(R.length))}else R=r(S);return 0===i(R)?function(e,s,r,t,i){var d,m;return d=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,d,0,t,{readonly:i})}(E,y,t(R,z),w,!c):(u=function(e,s,r){var t,n,i;for(t=e.data,n=r,i=0;i\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;wzCAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,uIAAwId,EAAMe,KAAM,KAAOrB,EAAES,QAM5L,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,mEAAoEd,EAAMe,KAAM,OAG/GT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e63cf96..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b32816a8307321288c72ffb50857ea5d81b68876 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:53:35 +0000 Subject: [PATCH 071/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 45 files changed, 4873 insertions(+), 6140 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7622728 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 804aaac..90fd933 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", - "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/array-typed": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.0", - "@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", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aef0f3d --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 58729f6c55ea2caa566d371cd59c3be1f3cb7dce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:26:49 +0000 Subject: [PATCH 072/143] 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 7c0f5db..6a187cc 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs'; ``` #### slice( x, slice, strict, writable ) @@ -138,7 +138,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From b2d03234d1ea04dbc511feb51a9bba7c6184f390 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:26:49 +0000 Subject: [PATCH 073/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a187cc..f179ab5 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs'; ``` @@ -138,7 +143,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-base-slice@v0.2.1-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 63c418bfee5c55e83b2cb90a6a6514fc48a7e369 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:52:25 +0000 Subject: [PATCH 074/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 079bc3a..d595400 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 95527b2772a8a3a959024e85bdcd849c9156b10d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:35:24 +0000 Subject: [PATCH 075/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7622728..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aef0f3d..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a81bd37aec7353721af983c1b7c58b232a08c8fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:35:49 +0000 Subject: [PATCH 076/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6142 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 1e08a71..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:40:53.437Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ae5338d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index d595400..90fd933 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", - "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1aa82f3 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 67894a3eb3b6797060398807008d6a2b44971d9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:10:15 +0000 Subject: [PATCH 077/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 079bc3a..d595400 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 9ac74070902df42b709bde826035cc4c71c52bf7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:34:04 +0000 Subject: [PATCH 078/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ae5338d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1aa82f3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1c06aebf62ea9d83e231e97a34723b94d9a1a9ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:34:20 +0000 Subject: [PATCH 079/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6145 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 5d10e3e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:59:10.738Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ae5338d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index d595400..90fd933 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", - "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1aa82f3 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 251a9efcaf7cd9d920d7238ccdad918327f7c993 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:28:07 +0000 Subject: [PATCH 080/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 079bc3a..d595400 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 006fe9316a103935127ddd1c9bcf326c43a1f961 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:50:33 +0000 Subject: [PATCH 081/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ae5338d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1aa82f3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b47a417999884f811d00a4427f0ec5de22c7dbef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:50:54 +0000 Subject: [PATCH 082/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 11 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 45 files changed, 4873 insertions(+), 6146 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 85203ee..0000000 --- a/dist/index.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){ -function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q -});var U=R();module.exports=U; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ae5338d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index d595400..90fd933 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.1", - "@stdlib/array-base-zeros": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.1", - "@stdlib/ndarray-base-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-offset": "^0.2.1", - "@stdlib/ndarray-base-order": "^0.2.1", - "@stdlib/ndarray-base-shape": "^0.2.1", - "@stdlib/ndarray-base-strides": "^0.2.1", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.1", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.1", - "@stdlib/slice-base-shape": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^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-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", - "@stdlib/slice-multi": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1aa82f3 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 f63dbda1e3a8c87b8d0559741fb5a638d536bac9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:44:45 +0000 Subject: [PATCH 083/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 581dc17..261aabd 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From e1ff0fd838d315ac8730d9c72b6830ad09628699 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:58:02 +0000 Subject: [PATCH 084/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ae5338d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1aa82f3..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dcfbe6f1e58ea0cfa9d60705b43100ffa16f57e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:58:20 +0000 Subject: [PATCH 085/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 45 files changed, 4873 insertions(+), 6293 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 261aabd..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^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.2", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 bcccd80f7167b6b5c23148a31800693fbe0020ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:05:55 +0000 Subject: [PATCH 086/143] 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 7948cf9..b2e2d7e 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs'; ``` #### slice( x, slice, strict, writable ) @@ -138,7 +138,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 770b8a5ba2d61e61e8002a2783fc221c1e0bdb49 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:05:56 +0000 Subject: [PATCH 087/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2e2d7e..c32945e 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs'; ``` @@ -138,7 +143,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-base-slice@v0.2.2-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From dd272e3680faaceb6c93e35159fa2de12c749da8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:58:34 +0000 Subject: [PATCH 088/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 3c17ae4..03f1a1c 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 714682ab44f7fb6677ed91391c48f886879f32d7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:53:28 +0000 Subject: [PATCH 089/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5c02431574002d411b178e9059dd20ad373a451f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:53:54 +0000 Subject: [PATCH 090/143] 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 | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6241 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 d433bc0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:51:29.416Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 03f1a1c..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 3cd8184b17a8b971b4319b5cddc7483b4559c75b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:22:02 +0000 Subject: [PATCH 091/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index e8f6028..260e413 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^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 0b1528c430edd8ae1cfa778629923e166c64fb91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:07 +0000 Subject: [PATCH 092/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cd881a2e0bfdcd4c37f7533630beec25e012c9ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:46:38 +0000 Subject: [PATCH 093/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6294 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 725c872..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:05.407Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 260e413..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 9c4684638b5712ed4b3ee3b579d31e2f20a5b52f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:39:38 +0000 Subject: [PATCH 094/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index e8f6028..260e413 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^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 4530a931010a9657992a8cb110c63e9c4a3eee0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:18:26 +0000 Subject: [PATCH 095/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 730066744a5a770540696c213eadeeaf10827adf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:18:50 +0000 Subject: [PATCH 096/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6294 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 18e0624..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:30:15.524Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 260e413..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 31f35a4b2c5f93ffe1a98a65526c30d5f44e9b25 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:26:08 +0000 Subject: [PATCH 097/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index e8f6028..260e413 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^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 b4a1d005d9d9fe5e89e981bbe26db9863862893a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:26:11 +0000 Subject: [PATCH 098/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 08aba5135a21a523612a6a04bc8a9618d89f94a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:26:38 +0000 Subject: [PATCH 099/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ----- 46 files changed, 4873 insertions(+), 6294 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 7c16efc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:33:26.444Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 260e413..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^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/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 2f6de5a569446a61729d1a2a10ba493e7084f217 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:42:49 +0000 Subject: [PATCH 100/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 7dab68afd2df624cf9fd171569b69b53eac0714c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:49:57 +0000 Subject: [PATCH 101/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4e2bc9430b62e7aba90d5e3c7f2d46bf57e2abfd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:50:36 +0000 Subject: [PATCH 102/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6399 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 b587ea1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:43:12.876Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 58a8f6b7e15048af45a1c843733e96b1f7fb1e50 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:38:00 +0000 Subject: [PATCH 103/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 0267972df0955a4e1995d90a7f2eee40c0cb7b48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:46:46 +0000 Subject: [PATCH 104/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dba1840649c21d1faeda9655b80c05c5894582cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:47:08 +0000 Subject: [PATCH 105/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6399 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 9fbceb1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:35:29.712Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..041a3cf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 b88e325cbd7665561e6048fe562701c0ef7914c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 14:44:16 +0000 Subject: [PATCH 106/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From cdbe2b20707bf59d4fd7adadacf0b9a4e933ec79 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 14:44:55 +0000 Subject: [PATCH 107/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 041a3cf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 15dcb950fdedaded6a7f310d3fca9f50efedc317 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Feb 2025 14:45:16 +0000 Subject: [PATCH 108/143] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6398 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 9e8bcaf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-02T14:43:48.706Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cda90fb..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..76573ed --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 2e93b6d79fa6c40c707a4170242d74b13547b00f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 00:53:34 +0000 Subject: [PATCH 109/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 24e26c98a08d53a79a0bcd9edca0b4e6fe294082 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:12:08 +0000 Subject: [PATCH 110/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 76573ed..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 53665980517d851229b3545a1bfb903cd5222ab1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:12:31 +0000 Subject: [PATCH 111/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6402 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 07f167b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T00:47:06.382Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..76573ed --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 3646cd4dd168764f6c1bbcb06b011f44d50ceb85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 14 Apr 2025 00:39:42 +0000 Subject: [PATCH 112/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d4ee751cabdf54fe92a2d521b02d263b4b45d67e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 14 Apr 2025 00:41:10 +0000 Subject: [PATCH 113/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 76573ed..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fac540c17212bf29cdb69475b0e8efe490c3724e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 14 Apr 2025 00:41:45 +0000 Subject: [PATCH 114/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6402 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 d6f193f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-14T00:38:24.068Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..76573ed --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 96a48ea36d13de12588fc27fe78a9357d76fe703 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:31:00 +0000 Subject: [PATCH 115/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index f9478fc..50e4b40 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 85a2ba66cdd1efe34ab43b0a4891c4aede57c0f8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:31:20 +0000 Subject: [PATCH 116/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 76573ed..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d81429c33f2dc19e88c33fb135f6016345d7ec9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 5 May 2025 00:31:41 +0000 Subject: [PATCH 117/143] 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 | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6402 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 2249bd6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-05T00:30:36.621Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..76573ed --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 50e4b40..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.2", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..97a7f45 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 9cb4ac8e653fff6d2c1b5c8e58cfd09626b2a717 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 06:48:39 +0000 Subject: [PATCH 118/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 592ce03..2dfbc1b 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", "@stdlib/slice-base-normalize-multi-slice": "^0.2.3", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From b7cdf8baf3690b2ab09fb62058abcddff220dd76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:52:23 +0000 Subject: [PATCH 119/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 76573ed..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 97a7f45..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bec6be7fe5bf46de8ed1b4bdac24406e4631da2d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 31 Jan 2026 07:52:53 +0000 Subject: [PATCH 120/143] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 46 files changed, 4873 insertions(+), 6506 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 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/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..35cc1f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 2dfbc1b..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.2", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.3", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.1", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..12bdf1c --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 e37107cf941d4eb967b0da5a9f20a12d26e90cd9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 02:57:27 +0000 Subject: [PATCH 121/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 0162b0f..3ffc44a 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.3", "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 2e94f8fa69056409810abeb852eaeacb8ff42ecc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 04:11:53 +0000 Subject: [PATCH 122/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 35cc1f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 12bdf1c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2a07c01f0653c49f65be8a671b994a77f000a2ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Feb 2026 04:12:22 +0000 Subject: [PATCH 123/143] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 108 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 131 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6507 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.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 63e2793..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-02-02T02:27:14.377Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..eb73910 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 3ffc44a..5c075a8 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.2", - "@stdlib/array-base-zeros": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.2", - "@stdlib/ndarray-base-dtype": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-offset": "^0.2.2", - "@stdlib/ndarray-base-order": "^0.2.2", - "@stdlib/ndarray-base-shape": "^0.2.2", - "@stdlib/ndarray-base-strides": "^0.2.2", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.3", - "@stdlib/slice-base-shape": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.1", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.3.0", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.3.0", - "@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", - "@stdlib/slice-multi": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2108efa --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 832d43bfa9186ae3c9551a0e52d909562d924739 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 8 Feb 2026 23:19:09 +0000 Subject: [PATCH 124/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 29c969a..7643866 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 4987395cb98b9cf5cc4d85611dd13c91d490fc08 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:12:11 +0000 Subject: [PATCH 125/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index eb73910..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.3-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2108efa..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1edc3ed2b6eca5a3a6038947da1d8019c157e831 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:12:33 +0000 Subject: [PATCH 126/143] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 141 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 46 files changed, 4873 insertions(+), 6509 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 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/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8e56b04 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 7643866..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-array": "^0.2.2", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a4ace1b --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 493b82f44393bdcd09e3efc657b18303f5ba994e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:38:03 +0000 Subject: [PATCH 127/143] Update README.md for ESM bundle v0.2.3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c53b84e..c629e36 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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs'; ``` #### slice( x, slice, strict, writable ) @@ -138,7 +138,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-base-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 3f1756e2e8b16e4605b3b69c87bfca001207effa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Feb 2026 00:38:03 +0000 Subject: [PATCH 128/143] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c629e36..a413259 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-base-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-base-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.3-esm/index.mjs'; ``` @@ -138,7 +143,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-base-slice@v0.2.3-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 8e45911d4bf64f95ab0a5790ad783b4e0176acb5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:21:22 +0000 Subject: [PATCH 129/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 40b9208..ccbdcd8 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From a6d413485964112c67a18e6e9a8307276cf86e1b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:25:16 +0000 Subject: [PATCH 130/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8e56b04..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a4ace1b..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 59d4bd960ca878cbf50d10e11e1c7fc2654a3c02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 10 Apr 2026 03:25:42 +0000 Subject: [PATCH 131/143] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 141 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1073 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6521 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a36ce1d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-04-10T03:19:36.483Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c6f16ea..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1073 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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, false, false ); - if ( typeof v !== 'object' ) { - b.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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( '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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var v; - var 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 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4b08286 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index ccbdcd8..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1028ca2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 21392ab562cc5141876594e345b5daaa2e5505f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 18 May 2026 23:56:14 +0000 Subject: [PATCH 132/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 40b9208..ccbdcd8 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 6540a2c762cef694571aa93721ca402241d98b18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 19 May 2026 00:01:35 +0000 Subject: [PATCH 133/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b08286..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1028ca2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9017e9e7008bb50a684d199f0065232bff298bff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 19 May 2026 00:02:06 +0000 Subject: [PATCH 134/143] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 176 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1074 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 46 files changed, 4873 insertions(+), 6561 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 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/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 035f203..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1074 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::0d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::0d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4b08286 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index ccbdcd8..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1028ca2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 ea542938ed1dab1127170f6701001f198cef111a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 03:26:33 +0000 Subject: [PATCH 135/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 40b9208..ccbdcd8 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From bd7369114c87127685f3f6c2e5032c5786d1c969 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 03:44:50 +0000 Subject: [PATCH 136/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b08286..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1028ca2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d0c566c42651030c1788f1256eb9c01815de20ed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 21 May 2026 03:45:14 +0000 Subject: [PATCH 137/143] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 176 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1074 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6575 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8210ef2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-05-21T03:24:14.726Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 035f203..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1074 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::0d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::0d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 8199b74..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var p=f(function(W,h){"use strict";function b(e,a,u){var i,t,r;for(i=e.data,t=u,r=0;r0&&(s=C(s.length))}else s=D(v);return A(s)===0?P(l,n,q(s,c),d,!i):(r=K(v,t,r),s=q(s,c),s.length===0?new l(n,g(e),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(e),s,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index d618e2b..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4b08286 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index ccbdcd8..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1028ca2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 1116a7f3248363387840ce27641f164ed5709a03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Jul 2026 03:30:52 +0000 Subject: [PATCH 138/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 80c0eeb..4a8f9a2 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From 51e9929af7a25167f2012ef74d27786cb36cf951 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Jul 2026 03:46:33 +0000 Subject: [PATCH 139/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b08286..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1028ca2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 801c700ef0ed2eb566e4702164d6dfa748b7cf7c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Jul 2026 03:47:06 +0000 Subject: [PATCH 140/143] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 204 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 176 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1074 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6575 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 302093f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-07-01T03:28:44.260Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 035f203..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1074 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::0d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::0d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 acd40c4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(a,e){return function(){try{return e||a((e={exports:{}}).exports,e),e.exports}catch(s){throw e=0,s}}};var p=f(function(W,h){"use strict";function b(a,e,s){var i,t,r;for(i=a.data,t=s,r=0;r0&&(u=C(u.length))}else u=D(v);return A(u)===0?P(l,n,q(u,c),d,!i):(r=K(v,t,r),u=q(u,c),u.length===0?new l(n,g(a),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(a),u,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 0756834..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4b08286 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4a8f9a2..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1028ca2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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 d5d44e8cc8d2f6b729020f2de7e04bb45b8f596e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:28:31 +0000 Subject: [PATCH 141/143] Transform error messages --- lib/main.js | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 216c524..ed88f6b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -32,7 +32,7 @@ var getStrides = require( '@stdlib/ndarray-base-strides' ); var getOffset = require( '@stdlib/ndarray-base-offset' ); var getOrder = require( '@stdlib/ndarray-base-order' ); var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var sliceStart = require( './slice_start.js' ); var slice2strides = require( './slice_strides.js' ); var empty = require( './empty.js' ); @@ -105,7 +105,7 @@ function slice( x, s, strict, writable ) { // Ensure that the number of array dimensions matches the number of slices: if ( s.ndims !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.', shape.join( ',' ), s.ndims ) ); + throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); } // Resolve the output array constructor: ctor = x.constructor; @@ -125,7 +125,7 @@ function slice( x, s, strict, writable ) { // Check whether the slice exceeds array bounds... if ( ns.code ) { if ( strict ) { - throw new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) ); + throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); } // Normalize again, this time allowing for out-of-bounds indices: ns = normalizeMultiSlice( s, shape, false ); diff --git a/package.json b/package.json index 80c0eeb..4a8f9a2 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/string-format": "^0.2.3", + "@stdlib/error-tools-fmtprodmsg": "^0.2.3", "@stdlib/types": "^0.5.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.3" }, From b797277987a54f6913e4d02bd9004c644fae7857 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:59:07 +0000 Subject: [PATCH 142/143] Remove files --- index.d.ts | 587 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5434 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 1e95673..0000000 --- a/index.d.ts +++ /dev/null @@ -1,587 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { MultiSlice } from '@stdlib/types/slice'; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // 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, strict: boolean, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, strict: boolean, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, strict: boolean, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, strict: boolean, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param strict - boolean indicating whether to enforce strict bounds checking -* @param writable - boolean indicating whether a returned array should be writable -* @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 s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, strict: boolean, writable: boolean ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4b08286..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1028ca2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fd1f78a0b0cf12f4ea7c5c1215bc79c3fa09fd98 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 19 Aug 2026 03:59:41 +0000 Subject: [PATCH 143/143] Auto-generated commit --- .editorconfig | 189 - .eslintrc.js | 1 - .gitattributes | 68 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 821 --- .github/workflows/publish.yml | 261 - .github/workflows/test.yml | 101 - .github/workflows/test_bundles.yml | 213 - .github/workflows/test_coverage.yml | 142 - .github/workflows/test_install.yml | 94 - .github/workflows/test_published_package.yml | 115 - .gitignore | 205 - .npmignore | 229 - .npmrc | 44 - CHANGELOG.md | 176 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 55 +- SECURITY.md | 5 - benchmark/benchmark.js | 1074 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 43 - docs/types/test.ts | 142 - examples/index.js | 92 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/empty.js | 58 - lib/index.js | 67 - lib/main.js | 172 - lib/slice_start.js | 48 - lib/slice_strides.js | 60 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 998 ---- 47 files changed, 4873 insertions(+), 6576 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/empty.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/slice_start.js delete mode 100644 lib/slice_strides.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 80f3fca..0000000 --- a/.editorconfig +++ /dev/null @@ -1,189 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Ignore generated lock files for GitHub Agentic Workflows: -[*.lock.yml] -charset = unset -end_of_line = unset -indent_style = unset -indent_size = unset -trim_trailing_whitespace = unset -insert_final_newline = unset - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 24b327f..0000000 --- a/.gitattributes +++ /dev/null @@ -1,68 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation - -.github/workflows/*.lock.yml linguist-generated=true merge=ours diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e3ba253..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2026-08-19T03:20:48.674Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index e08a864..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 84a1109..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice) 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 83d50c4..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,821 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send notification to Zulip if job fails: - - name: 'Send notification to Zulip in case of failure' - # Pin action to full length commit SHA - uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5 # v1.0.2 - if: failure() - with: - api-key: ${{ secrets.ZULIP_API_KEY }} - email: 'github-actions-bot@stdlib.zulipchat.com' - organization-url: 'https://stdlib.zulipchat.com' - to: 'workflows-standalone' - type: 'stream' - topic: ${{ github.event.repository.name }} - content: | - :cross_mark: **${{ github.workflow }}** workflow failed - - **Repository:** [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) - **Run:** [View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -241,7 +232,7 @@ var a6 = ndarray2array( y6 ); ## 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]. @@ -304,7 +295,7 @@ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-slice/main/LICENSE -[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi +[@stdlib/slice/multi]: https://github.com/stdlib-js/slice-multi/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 035f203..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1074 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 format = require( '@stdlib/string-format' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( format( '%s::0d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::0d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::1d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,base,out-of-bounds', pkg ), 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( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::2d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::3d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::4d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,reduced', pkg ), 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, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,reduced', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,base,out-of-bounds', pkg ), 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, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( format( '%s::5d,non-base,out-of-bounds', pkg ), function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ - - 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, stdlib/line-closing-bracket-spacing */ - - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], s, false, false ); - if ( typeof v !== '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 08bbdce..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice" -%% click B href "https://github.com/stdlib-js/ndarray-base-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/slice -[production-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-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 acd40c4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var f=function(a,e){return function(){try{return e||a((e={exports:{}}).exports,e),e.exports}catch(s){throw e=0,s}}};var p=f(function(W,h){"use strict";function b(a,e,s){var i,t,r;for(i=a.data,t=s,r=0;r0&&(u=C(u.length))}else u=D(v);return A(u)===0?P(l,n,q(u,c),d,!i):(r=K(v,t,r),u=q(u,c),u.length===0?new l(n,g(a),[],[0],r,d,{readonly:!i}):(t=L(v,t,c),new l(n,g(a),u,t,r,d,{readonly:!i})))}O.exports=Q});var U=R();module.exports=U; -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 0756834..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/slice_start.js", "../lib/slice_strides.js", "../lib/empty.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* var Slice = require( '@stdlib/slice-ctor' );\n* var MultiSlice = require( '@stdlib/slice-multi' );\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice2strides;\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// MODULES //\n\nvar buffer = require( '@stdlib/ndarray-base-buffer' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = empty;\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// MODULES //\n\nvar normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' );\nvar nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' );\nvar sliceShape = require( '@stdlib/slice-base-shape' );\nvar take = require( '@stdlib/array-base-take-indexed' );\nvar zeros = require( '@stdlib/array-base-zeros' );\nvar numel = require( '@stdlib/ndarray-base-numel' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require( '@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\nvar sliceStart = require( './slice_start.js' );\nvar slice2strides = require( './slice_strides.js' );\nvar empty = require( './empty.js' );\n\n\n// MAIN //\n\n/**\n* Returns a view of an input ndarray.\n*\n* @param {ndarray} x - input array\n* @param {MultiSlice} s - multi-slice object\n* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking\n* @param {boolean} writable - boolean indicating whether a returned array should be writable\n* @throws {RangeError} number of slice dimensions must match the number of array dimensions\n* @throws {RangeError} slice exceeds array bounds\n* @returns {ndarray} ndarray view\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*\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\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.', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Slice exceeds array bounds. Array shape: (%s).', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\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 view of an input ndarray.\n*\n* @module @stdlib/ndarray-base-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-base-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, false, false );\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": "iIAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA+BA,SAASC,EAAYC,EAAOC,EAASC,EAAS,CAC7C,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAOH,EAAM,KACbI,EAAMF,EACAG,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7BD,GAAOH,EAASI,CAAE,EAAIF,EAAME,CAAE,EAAE,MAEjC,OAAOD,CACR,CAKAN,EAAO,QAAUC,IC/CjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAyCA,SAASC,EAAeC,EAAOC,EAASC,EAAQ,CAC/C,IAAIC,EACAC,EACAC,EACAC,EAIJ,IAFAH,EAAOH,EAAM,KACbI,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIH,EAAM,OAAQG,IAC9BC,EAAIJ,EAAOG,CAAE,EACbD,EAAI,KAAMH,EAAQK,CAAC,EAAIH,EAAKG,CAAC,EAAE,IAAK,EAErC,OAAOF,CACR,CAKAN,EAAO,QAAUC,IC3DjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,6BAA8B,EAChDC,EAAQ,QAAS,0BAA2B,EAgBhD,SAASC,EAAOC,EAAMC,EAAOC,EAAOC,EAAOC,EAAW,CACrD,IAAIC,EACAC,EAEJ,OAAAA,EAAQJ,EAAM,OACTI,IAAU,EACdD,EAAU,CAAE,CAAE,EAEdA,EAAUP,EAAOQ,CAAM,EAEjB,IAAIN,EAAMC,EAAOJ,EAAQI,EAAO,CAAE,EAAGC,EAAOG,EAAS,EAAGF,EAAO,CACrE,SAAYC,CACb,CAAC,CACF,CAKAR,EAAO,QAAUG,ICzDjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAsB,QAAS,0CAA2C,EAC1EC,EAAuB,QAAS,0CAA2C,EAC3EC,EAAa,QAAS,0BAA2B,EACjDC,EAAO,QAAS,iCAAkC,EAClDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAQ,QAAS,4BAA6B,EAC9CC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAgB,IAChBC,EAAQ,IAgDZ,SAASC,EAAOC,EAAGC,EAAGC,EAAQC,EAAW,CACxC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQjB,EAAUW,CAAE,EACpBO,EAAQjB,EAAUU,EAAG,EAAK,EAC1BI,EAAUb,EAAYS,EAAG,EAAK,EAC9BK,EAASb,EAAWQ,CAAE,EACtBQ,EAAQf,EAAUO,CAAE,EACpBU,EAAQH,EAAM,OAGTN,EAAE,QAAUS,EAChB,MAAM,IAAI,WAAYf,EAAQ,uIAAwIY,EAAM,KAAM,GAAI,EAAGN,EAAE,KAAM,CAAE,EAMpM,GAHAU,EAAOX,EAAE,YAGJU,IAAU,EACd,OAAO,IAAIC,EAAML,EAAOZ,EAASM,CAAE,EAAGO,EAAOH,EAASC,EAAQG,EAAO,CACpE,SAAY,CAACL,CACd,CAAC,EASF,GANAM,EAAQzB,EAAsBiB,CAAE,EAGhCY,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAK,EAGpCM,EAAG,KAAO,CACd,GAAKX,EACJ,MAAM,IAAI,WAAYP,EAAQ,mEAAoEY,EAAM,KAAM,GAAI,CAAE,CAAE,EAGvHM,EAAK9B,EAAqBkB,EAAGM,EAAO,EAAM,EAG1CK,EAAK3B,EAAY4B,CAAG,EAGfzB,EAAOF,EAAM0B,EAAIH,CAAM,CAAE,EAAI,IACjCG,EAAKzB,EAAOyB,EAAG,MAAO,EAExB,MAECA,EAAK3B,EAAY4B,CAAG,EAGrB,OAAKzB,EAAOwB,CAAG,IAAM,EACbd,EAAOa,EAAML,EAAOpB,EAAM0B,EAAIH,CAAM,EAAGD,EAAO,CAACL,CAAS,GAGhEE,EAAST,EAAYiB,EAAIT,EAASC,CAAO,EAGzCO,EAAK1B,EAAM0B,EAAIH,CAAM,EAGhBG,EAAG,SAAW,EACX,IAAID,EAAML,EAAOZ,EAASM,CAAE,EAAG,CAAC,EAAG,CAAE,CAAE,EAAGK,EAAQG,EAAO,CAC/D,SAAY,CAACL,CACd,CAAC,GAGFC,EAAUP,EAAegB,EAAIT,EAASK,CAAM,EAGrC,IAAIE,EAAML,EAAOZ,EAASM,CAAE,EAAGY,EAAIR,EAASC,EAAQG,EAAO,CACjE,SAAY,CAACL,CACd,CAAC,GACF,CAKArB,EAAO,QAAUiB,IC9GjB,IAAIe,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_slice_start", "__commonJSMin", "exports", "module", "sliceStart", "slice", "strides", "offset", "data", "idx", "i", "require_slice_strides", "__commonJSMin", "exports", "module", "slice2strides", "slice", "strides", "rdims", "data", "out", "i", "j", "require_empty", "__commonJSMin", "exports", "module", "buffer", "zeros", "empty", "ctor", "dtype", "shape", "order", "readonly", "strides", "ndims", "require_main", "__commonJSMin", "exports", "module", "normalizeMultiSlice", "nonreducedDimensions", "sliceShape", "take", "zeros", "numel", "getDType", "getShape", "getStrides", "getOffset", "getOrder", "getData", "format", "sliceStart", "slice2strides", "empty", "slice", "x", "s", "strict", "writable", "strides", "offset", "dtype", "shape", "order", "sdims", "ndims", "ctor", "sh", "ns", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8e24eea..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x, slice, strict, writable ) - Returns a view of an input ndarray. - - Parameters - ---------- - x: ndarray - Input array. - - slice: MultiSlice - Multi-slice object. - - strict: boolean - Boolean indicating whether to enforce strict bounds checking. - - writable: boolean - Boolean indicating whether a returned ndarray should be writable. This - parameter only applies to ndarray constructors which support read-only - instances. - - 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, false, false ) - - > 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 ff0345c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, false, false ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, false, false ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, false, false ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, false, false ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, false, false ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, false, false ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, false, false ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, false, false ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, false, false ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, false, false ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, true, true ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, true, true ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, true, true ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, true, true ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, true, true ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, true, true ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, true, true ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, true, true ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, true, true ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, true, true ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, true, 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, false, false ); // $ExpectError - slice( 10, s, false, false ); // $ExpectError - slice( false, s, false, false ); // $ExpectError - slice( true, s, false, false ); // $ExpectError - slice( null, s, false, false ); // $ExpectError - slice( [], s, false, false ); // $ExpectError - slice( {}, s, false, false ); // $ExpectError - slice( ( x: number ): number => x, s, false, false ); // $ExpectError - - slice( '10', s, true, true ); // $ExpectError - slice( 10, s, true, true ); // $ExpectError - slice( false, s, true, true ); // $ExpectError - slice( true, s, true, true ); // $ExpectError - slice( null, s, true, true ); // $ExpectError - slice( [], s, true, true ); // $ExpectError - slice( {}, s, true, true ); // $ExpectError - slice( ( x: number ): number => x, s, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a multi-slice object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5', false, false ); // $ExpectError - slice( x, 5, false, false ); // $ExpectError - slice( x, false, false, false ); // $ExpectError - slice( x, true, false, false ); // $ExpectError - slice( x, null, false, false ); // $ExpectError - slice( x, undefined, false, false ); // $ExpectError - slice( x, [ '5' ], false, false ); // $ExpectError - slice( x, {}, false, false ); // $ExpectError - slice( x, ( x: number ): number => x, false, false ); // $ExpectError - - slice( x, '5', true, true ); // $ExpectError - slice( x, 5, true, true ); // $ExpectError - slice( x, false, true, true ); // $ExpectError - slice( x, true, true, true ); // $ExpectError - slice( x, null, true, true ); // $ExpectError - slice( x, undefined, true, true ); // $ExpectError - slice( x, [ '5' ], true, true ); // $ExpectError - slice( x, {}, true, true ); // $ExpectError - slice( x, ( x: number ): number => x, true, true ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5', false ); // $ExpectError - slice( x, s, 5, false ); // $ExpectError - slice( x, s, null, false ); // $ExpectError - slice( x, s, undefined, false ); // $ExpectError - slice( x, s, [ '5' ], false ); // $ExpectError - slice( x, s, {}, false ); // $ExpectError - slice( x, s, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, false, '5' ); // $ExpectError - slice( x, s, false, 5 ); // $ExpectError - slice( x, s, false, null ); // $ExpectError - slice( x, s, false, undefined ); // $ExpectError - slice( x, s, false, [ '5' ] ); // $ExpectError - slice( x, s, false, {} ); // $ExpectError - slice( x, s, false, ( 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( x ); // $ExpectError - slice( x, s ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, false, false, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 997a33a..0000000 --- a/examples/index.js +++ /dev/null @@ -1,92 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// 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, false, false ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5, false, false ); -// 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, false, false ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 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 65226cc..1e95673 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { MultiSlice } from '@stdlib/types/slice'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4b08286 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2026 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-normalize-multi-slice@v0.2.4-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-nonreduced-dimensions@v0.2.3-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-shape@v0.2.3-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-take-indexed@v0.2.3-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zeros@v0.2.3-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.3-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype@v0.2.3-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape@v0.2.3-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides@v0.2.3-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-offset@v0.2.3-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-order@v0.2.3-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-data-buffer@v0.2.3-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.3-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.1-esm/index.mjs";function f(f,v,b,c){var g,u,x,y,w,E,R,z,k,q;if(x=i(f),y=m(f,!0),g=o(f,!0),u=a(f),w=l(f),R=y.length,v.ndims!==R)throw new RangeError(h("1jREt",y.join(","),v.ndims));if(z=f.constructor,0===R)return new z(x,j(f),y,g,u,w,{readonly:!c});if(E=s(v),(q=e(v,y,!0)).code){if(b)throw new RangeError(h("1jREz",y.join(",")));q=e(v,y,!1),k=r(q),d(t(k,E))>0&&(k=n(k.length))}else k=r(q);return 0===d(k)?function(e,s,r,t,d){var i,m;return i=0===(m=r.length)?[0]:n(m),new e(s,p(s,0),r,i,0,t,{readonly:d})}(z,x,t(k,E),w,!c):(u=function(e,s,r){var t,n,d;for(t=e.data,n=r,d=0;d\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, false, false );\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, strict, writable ) {\n\tvar strides;\n\tvar offset;\n\tvar dtype;\n\tvar shape;\n\tvar order;\n\tvar sdims;\n\tvar ndims;\n\tvar ctor;\n\tvar sh;\n\tvar ns;\n\n\t// Retrieve array meta data:\n\tdtype = getDType( x );\n\tshape = getShape( x, true );\n\tstrides = getStrides( x, true );\n\toffset = getOffset( x );\n\torder = getOrder( x );\n\tndims = shape.length;\n\n\t// Ensure that the number of array dimensions matches the number of slices:\n\tif ( s.ndims !== ndims ) {\n\t\tthrow new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) );\n\t}\n\t// Resolve the output array constructor:\n\tctor = x.constructor;\n\n\t// If provided a zero-dimensional input array, return a zero-dimensional array view...\n\tif ( ndims === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), shape, strides, offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Resolve the indices of the non-reduced dimensions:\n\tsdims = nonreducedDimensions( s );\n\n\t// Normalize the slice object based on the array shape:\n\tns = normalizeMultiSlice( s, shape, true );\n\n\t// Check whether the slice exceeds array bounds...\n\tif ( ns.code ) {\n\t\tif ( strict ) {\n\t\t\tthrow new RangeError( format( '1jREz', shape.join( ',' ) ) );\n\t\t}\n\t\t// Normalize again, this time allowing for out-of-bounds indices:\n\t\tns = normalizeMultiSlice( s, shape, false );\n\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\n\t\t// If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros:\n\t\tif ( numel( take( sh, sdims ) ) > 0 ) {\n\t\t\tsh = zeros( sh.length );\n\t\t}\n\t} else {\n\t\t// Compute the slice shape:\n\t\tsh = sliceShape( ns );\n\t}\n\t// If the slice does not contain any elements, return an empty array...\n\tif ( numel( sh ) === 0 ) {\n\t\treturn empty( ctor, dtype, take( sh, sdims ), order, !writable );\n\t}\n\t// Resolve the index offset of the first element indexed by the slice:\n\toffset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind\n\n\t// Remove reduced dimensions from the slice shape:\n\tsh = take( sh, sdims );\n\n\t// If all dimensions were reduced, return a zero-dimensional array...\n\tif ( sh.length === 0 ) {\n\t\treturn new ctor( dtype, getData( x ), [], [ 0 ], offset, order, {\n\t\t\t'readonly': !writable\n\t\t});\n\t}\n\t// Update strides according to slice steps:\n\tstrides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides???\n\n\t// Return a slice view:\n\treturn new ctor( dtype, getData( x ), sh, strides, offset, order, {\n\t\t'readonly': !writable\n\t});\n}\n\n\n// EXPORTS //\n\nexport default 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// MODULES //\n\nimport buffer from '@stdlib/ndarray-base-buffer';\nimport zeros from '@stdlib/array-base-zeros';\n\n\n// MAIN //\n\n/**\n* Returns an empty n-dimensional ndarray.\n*\n* @private\n* @param {Function} ctor - ndarray constructor\n* @param {string} dtype - array data type\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {string} order - layout order\n* @param {boolean} readonly - boolean indicating whether a returned array should be read-only\n* @returns {ndarray} empty ndarray\n*/\nfunction empty( ctor, dtype, shape, order, readonly ) {\n\tvar strides;\n\tvar ndims;\n\n\tndims = shape.length;\n\tif ( ndims === 0 ) {\n\t\tstrides = [ 0 ];\n\t} else {\n\t\tstrides = zeros( ndims );\n\t}\n\treturn new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, {\n\t\t'readonly': readonly\n\t});\n}\n\n\n// EXPORTS //\n\nexport default empty;\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// MAIN //\n\n/**\n* Resolves the index offset of the first element indexed by a normalized multi-slice.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeInteger} offset - array index offset\n* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object\n*/\nfunction sliceStart( slice, strides, offset ) {\n\tvar data;\n\tvar idx;\n\tvar i;\n\n\tdata = slice.data;\n\tidx = offset;\n\tfor ( i = 0; i < data.length; i++ ) {\n\t\tidx += strides[ i ] * data[ i ].start;\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sliceStart;\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// MAIN //\n\n/**\n* Resolves slice strides for a provided normalized multi-slice object.\n*\n* @private\n* @param {MultiSlice} slice - normalized multi-slice object\n* @param {IntegerArray} strides - array strides\n* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions\n* @returns {IntegerArray} slice strides\n*\n* @example\n* import Slice from '@stdlib/slice-ctor';\n* import MultiSlice from '@stdlib/slice-multi';\n*\n* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) );\n* // returns \n*\n* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] );\n* // returns [ -4 ]\n*/\nfunction slice2strides( slice, strides, rdims ) {\n\tvar data;\n\tvar out;\n\tvar i;\n\tvar j;\n\n\tdata = slice.data;\n\tout = [];\n\tfor ( i = 0; i < rdims.length; i++ ) {\n\t\tj = rdims[ i ];\n\t\tout.push( strides[j] * data[j].step );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default slice2strides;\n"],"names":["slice","x","s","strict","writable","strides","offset","dtype","shape","order","sdims","ndims","ctor","sh","ns","getDType","getShape","getStrides","getOffset","getOrder","length","RangeError","format","join","constructor","getData","readonly","nonreducedDimensions","normalizeMultiSlice","code","sliceShape","numel","take","zeros","buffer","empty","data","idx","i","start","sliceStart","rdims","out","j","push","step","slice2strides"],"mappings":";;i0CAqFA,SAASA,EAAOC,EAAGC,EAAGC,EAAQC,GAC7B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAWJ,GARAP,EAAQQ,EAAUd,GAClBO,EAAQQ,EAAUf,GAAG,GACrBI,EAAUY,EAAYhB,GAAG,GACzBK,EAASY,EAAWjB,GACpBQ,EAAQU,EAAUlB,GAClBU,EAAQH,EAAMY,OAGTlB,EAAES,QAAUA,EAChB,MAAM,IAAIU,WAAYC,EAAQ,QAASd,EAAMe,KAAM,KAAOrB,EAAES,QAM7D,GAHAC,EAAOX,EAAEuB,YAGM,IAAVb,EACJ,OAAO,IAAIC,EAAML,EAAOkB,EAASxB,GAAKO,EAAOH,EAASC,EAAQG,EAAO,CACpEiB,UAAatB,IAUf,GANAM,EAAQiB,EAAsBzB,IAG9BY,EAAKc,EAAqB1B,EAAGM,GAAO,IAG5BqB,KAAO,CACd,GAAK1B,EACJ,MAAM,IAAIkB,WAAYC,EAAQ,QAASd,EAAMe,KAAM,OAGpDT,EAAKc,EAAqB1B,EAAGM,GAAO,GAGpCK,EAAKiB,EAAYhB,GAGZiB,EAAOC,EAAMnB,EAAIH,IAAY,IACjCG,EAAKoB,EAAOpB,EAAGO,QAElB,MAEEP,EAAKiB,EAAYhB,GAGlB,OAAqB,IAAhBiB,EAAOlB,GCzGb,SAAgBD,EAAML,EAAOC,EAAOC,EAAOiB,GAC1C,IAAIrB,EACAM,EAQJ,OAJCN,EADc,KADfM,EAAQH,EAAMY,QAEH,CAAE,GAEFa,EAAOtB,GAEX,IAAIC,EAAML,EAAO2B,EAAQ3B,EAAO,GAAKC,EAAOH,EAAS,EAAGI,EAAO,CACrEiB,SAAYA,GAEd,CD6FSS,CAAOvB,EAAML,EAAOyB,EAAMnB,EAAIH,GAASD,GAAQL,IAGvDE,EErHD,SAAqBN,EAAOK,EAASC,GACpC,IAAI8B,EACAC,EACAC,EAIJ,IAFAF,EAAOpC,EAAMoC,KACbC,EAAM/B,EACAgC,EAAI,EAAGA,EAAIF,EAAKhB,OAAQkB,IAC7BD,GAAOhC,EAASiC,GAAMF,EAAME,GAAIC,MAEjC,OAAOF,CACR,CF0GUG,CAAY1B,EAAIT,EAASC,GAMf,KAHnBO,EAAKmB,EAAMnB,EAAIH,IAGPU,OACA,IAAIR,EAAML,EAAOkB,EAASxB,GAAK,GAAI,CAAE,GAAKK,EAAQG,EAAO,CAC/DiB,UAAatB,KAIfC,EGvHD,SAAwBL,EAAOK,EAASoC,GACvC,IAAIL,EACAM,EACAJ,EACAK,EAIJ,IAFAP,EAAOpC,EAAMoC,KACbM,EAAM,GACAJ,EAAI,EAAGA,EAAIG,EAAMrB,OAAQkB,IAC9BK,EAAIF,EAAOH,GACXI,EAAIE,KAAMvC,EAAQsC,GAAKP,EAAKO,GAAGE,MAEhC,OAAOH,CACR,CH0GWI,CAAehC,EAAIT,EAASK,GAG/B,IAAIE,EAAML,EAAOkB,EAASxB,GAAKY,EAAIR,EAASC,EAAQG,EAAO,CACjEiB,UAAatB,KAEf"} \ No newline at end of file diff --git a/lib/empty.js b/lib/empty.js deleted file mode 100644 index 4dff752..0000000 --- a/lib/empty.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var buffer = require( '@stdlib/ndarray-base-buffer' ); -var zeros = require( '@stdlib/array-base-zeros' ); - - -// MAIN // - -/** -* Returns an empty n-dimensional ndarray. -* -* @private -* @param {Function} ctor - ndarray constructor -* @param {string} dtype - array data type -* @param {NonNegativeIntegerArray} shape - array shape -* @param {string} order - layout order -* @param {boolean} readonly - boolean indicating whether a returned array should be read-only -* @returns {ndarray} empty ndarray -*/ -function empty( ctor, dtype, shape, order, readonly ) { - var strides; - var ndims; - - ndims = shape.length; - if ( ndims === 0 ) { - strides = [ 0 ]; - } else { - strides = zeros( ndims ); - } - return new ctor( dtype, buffer( dtype, 0 ), shape, strides, 0, order, { - 'readonly': readonly - }); -} - - -// EXPORTS // - -module.exports = empty; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 5d5347a..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 view of an input ndarray. -* -* @module @stdlib/ndarray-base-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-base-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, false, false ); -* // 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 ed88f6b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,172 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var normalizeMultiSlice = require( '@stdlib/slice-base-normalize-multi-slice' ); -var nonreducedDimensions = require( '@stdlib/slice-base-nonreduced-dimensions' ); -var sliceShape = require( '@stdlib/slice-base-shape' ); -var take = require( '@stdlib/array-base-take-indexed' ); -var zeros = require( '@stdlib/array-base-zeros' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var getDType = require( '@stdlib/ndarray-base-dtype' ); -var getShape = require( '@stdlib/ndarray-base-shape' ); -var getStrides = require( '@stdlib/ndarray-base-strides' ); -var getOffset = require( '@stdlib/ndarray-base-offset' ); -var getOrder = require( '@stdlib/ndarray-base-order' ); -var getData = require( '@stdlib/ndarray-base-data-buffer' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var sliceStart = require( './slice_start.js' ); -var slice2strides = require( './slice_strides.js' ); -var empty = require( './empty.js' ); - - -// MAIN // - -/** -* Returns a view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {MultiSlice} s - multi-slice object -* @param {boolean} strict - boolean indicating whether to enforce strict bounds checking -* @param {boolean} writable - boolean indicating whether a returned array should be writable -* @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, false, false ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, s, strict, writable ) { - var strides; - var offset; - var dtype; - var shape; - var order; - var sdims; - var ndims; - var ctor; - var sh; - var ns; - - // Retrieve array meta data: - dtype = getDType( x ); - shape = getShape( x, true ); - strides = getStrides( x, true ); - offset = getOffset( x ); - order = getOrder( x ); - ndims = shape.length; - - // Ensure that the number of array dimensions matches the number of slices: - if ( s.ndims !== ndims ) { - throw new RangeError( format( '1jREt', shape.join( ',' ), s.ndims ) ); - } - // Resolve the output array constructor: - ctor = x.constructor; - - // If provided a zero-dimensional input array, return a zero-dimensional array view... - if ( ndims === 0 ) { - return new ctor( dtype, getData( x ), shape, strides, offset, order, { - 'readonly': !writable - }); - } - // Resolve the indices of the non-reduced dimensions: - sdims = nonreducedDimensions( s ); - - // Normalize the slice object based on the array shape: - ns = normalizeMultiSlice( s, shape, true ); - - // Check whether the slice exceeds array bounds... - if ( ns.code ) { - if ( strict ) { - throw new RangeError( format( '1jREz', shape.join( ',' ) ) ); - } - // Normalize again, this time allowing for out-of-bounds indices: - ns = normalizeMultiSlice( s, shape, false ); - - // Compute the slice shape: - sh = sliceShape( ns ); - - // If the non-reduced dimensions contain elements, this means that at least one reduced dimension exceeded array bounds; in which case, we generate a shape containing zeros: - if ( numel( take( sh, sdims ) ) > 0 ) { - sh = zeros( sh.length ); - } - } else { - // Compute the slice shape: - sh = sliceShape( ns ); - } - // If the slice does not contain any elements, return an empty array... - if ( numel( sh ) === 0 ) { - return empty( ctor, dtype, take( sh, sdims ), order, !writable ); - } - // Resolve the index offset of the first element indexed by the slice: - offset = sliceStart( ns, strides, offset ); // TODO: @stdlib/ndarray/base/sind2bind - - // Remove reduced dimensions from the slice shape: - sh = take( sh, sdims ); - - // If all dimensions were reduced, return a zero-dimensional array... - if ( sh.length === 0 ) { - return new ctor( dtype, getData( x ), [], [ 0 ], offset, order, { - 'readonly': !writable - }); - } - // Update strides according to slice steps: - strides = slice2strides( ns, strides, sdims ); // TODO: @stdlib/ndarray/base/slice2strides??? - - // Return a slice view: - return new ctor( dtype, getData( x ), sh, strides, offset, order, { - 'readonly': !writable - }); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/lib/slice_start.js b/lib/slice_start.js deleted file mode 100644 index 5e86eba..0000000 --- a/lib/slice_start.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves the index offset of the first element indexed by a normalized multi-slice. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeInteger} offset - array index offset -* @returns {NonNegativeInteger} index offset of the first element indexed by a normalized multi-slice object -*/ -function sliceStart( slice, strides, offset ) { - var data; - var idx; - var i; - - data = slice.data; - idx = offset; - for ( i = 0; i < data.length; i++ ) { - idx += strides[ i ] * data[ i ].start; - } - return idx; -} - - -// EXPORTS // - -module.exports = sliceStart; diff --git a/lib/slice_strides.js b/lib/slice_strides.js deleted file mode 100644 index eb6680e..0000000 --- a/lib/slice_strides.js +++ /dev/null @@ -1,60 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Resolves slice strides for a provided normalized multi-slice object. -* -* @private -* @param {MultiSlice} slice - normalized multi-slice object -* @param {IntegerArray} strides - array strides -* @param {NonNegativeIntegerArray} rdims - indices of non-reduced dimensions -* @returns {IntegerArray} slice strides -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* -* var s = new MultiSlice( new Slice( 2, 3, 1 ), new Slice( 10, null, -2 ) ); -* // returns -* -* var strides = slice2strides( s, [ 8, 2 ], [ 1 ] ); -* // returns [ -4 ] -*/ -function slice2strides( slice, strides, rdims ) { - var data; - var out; - var i; - var j; - - data = slice.data; - out = []; - for ( i = 0; i < rdims.length; i++ ) { - j = rdims[ i ]; - out.push( strides[j] * data[j].step ); - } - return out; -} - - -// EXPORTS // - -module.exports = slice2strides; diff --git a/package.json b/package.json index 4a8f9a2..5659951 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.3", "description": "Return a 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,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-take-indexed": "^0.2.3", - "@stdlib/array-base-zeros": "^0.2.3", - "@stdlib/ndarray-base-buffer": "^0.3.1", - "@stdlib/ndarray-base-data-buffer": "^0.2.3", - "@stdlib/ndarray-base-dtype": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.3", - "@stdlib/ndarray-base-offset": "^0.2.3", - "@stdlib/ndarray-base-order": "^0.2.3", - "@stdlib/ndarray-base-shape": "^0.2.3", - "@stdlib/ndarray-base-strides": "^0.2.3", - "@stdlib/slice-base-nonreduced-dimensions": "^0.2.3", - "@stdlib/slice-base-normalize-multi-slice": "^0.2.4", - "@stdlib/slice-base-shape": "^0.2.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3", - "@stdlib/types": "^0.5.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.3" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.2", - "@stdlib/array-typed": "^0.3.2", - "@stdlib/assert-is-ndarray-like": "^0.2.3", - "@stdlib/ndarray-array": "^0.2.3", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.3", - "@stdlib/ndarray-base-ctor": "^0.3.1", - "@stdlib/ndarray-base-empty": "^0.3.2", - "@stdlib/ndarray-base-from-scalar": "^0.2.3", - "@stdlib/ndarray-ctor": "^0.3.1", - "@stdlib/ndarray-empty": "^0.3.1", - "@stdlib/ndarray-to-array": "^0.2.2", - "@stdlib/ndarray-zeros": "^0.3.1", - "@stdlib/slice-ctor": "^0.2.3", - "@stdlib/slice-multi": "^0.2.3", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.3" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1028ca2 --- /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 0c8010e..0000000 --- a/test/test.js +++ /dev/null @@ -1,998 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 */ - -'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 the number of slice dimensions does not match the number of array dimensions (strict=false)', 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, false, false ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (strict=true)', 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, true, false ); - }; - } -}); - -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, true, false ); - }; - } -}); - -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 ], false, 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)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s, true, false ); - 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, true, false ); - 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, read-only)', 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, true, false ); - 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( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, read-only)', 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, true, false ); - 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, writable)', 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, true, true ); - 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 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, read-only)', 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, true, false ); - 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, true, false ); - 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, true, false ); - 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, true, false ); - 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( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base, offset, writable)', 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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, '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, true, true ); - 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 ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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)', 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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, true, false ); - - 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(); -});