From 73447ab46d7ffdeedd3149cb160372e4255c2e8d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:35:21 +0000 Subject: [PATCH 01/61] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2773cb7..abd5dc5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.1.1", "@stdlib/ndarray-base-slice-from": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From e294f725ebfbf3d18e6d55167e06bb858e4deb6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:36:34 +0000 Subject: [PATCH 02/61] 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 | 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.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ----- 43 files changed, 6208 insertions(+), 6313 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 0b6bd30..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: '56 8 * * 6' - - # 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 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 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 + + ```
@@ -281,7 +274,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -341,7 +334,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm
diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c03e215..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 f46020f..d891b01 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e63b82c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 f5588e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index abd5dc5..8b77114 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-null": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-undefined": "^0.1.1", - "@stdlib/ndarray-base-slice-from": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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..e1e1cea --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 90cbd97b32c687fa2b558959718a3b10ca130879 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:37:07 +0000 Subject: [PATCH 03/61] 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 a225ad1..af45dea 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.1.0-esm/index.mjs'; ``` #### sliceFrom( x, ...start\[, options] ) @@ -209,7 +209,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.1.0-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From f0cb83b750a3278d9d0cc3284411730389d7f94d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Dec 2023 02:37:07 +0000 Subject: [PATCH 04/61] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af45dea..52f4ccf 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice-from/tags). For example, + ```javascript import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.1.0-esm/index.mjs'; ``` @@ -209,7 +214,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.1.0-esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 9c066faeb30a8efe7369b552b2fc0a94145a1e51 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:37:31 +0000 Subject: [PATCH 05/61] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2773cb7..abd5dc5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.1.1", "@stdlib/ndarray-base-slice-from": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 89e17ee1bdac5e65d4113401c1fefdda31566c27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:39:29 +0000 Subject: [PATCH 06/61] Remove files --- index.d.ts | 1050 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7232 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 d891b01..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e63b82c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e1e1cea..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From da8ad090456ce5b3c805afc82a6d7c3c1f97964e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 06:40:28 +0000 Subject: [PATCH 07/61] 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 | 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 | 61 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ----- 43 files changed, 6212 insertions(+), 6317 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 d97bbf3..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: '56 8 * * 6' - - # 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 + + ```
@@ -291,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -351,17 +344,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c03e215..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 f46020f..d891b01 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e63b82c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 f5588e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index abd5dc5..8b77114 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-null": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-undefined": "^0.1.1", - "@stdlib/ndarray-base-slice-from": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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..33e2176 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 0e351671c5badec76f25ae8e1f0392ec20ef9b30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:01:04 +0000 Subject: [PATCH 08/61] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2773cb7..abd5dc5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.1.1", "@stdlib/ndarray-base-slice-from": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From b2ef0f9748c1eed421a5d53358e10db2868271b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:39:56 +0000 Subject: [PATCH 09/61] Remove files --- index.d.ts | 1050 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7232 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 d891b01..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e63b82c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 33e2176..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 96eeaddb5ce12fbc8854e46091e3272b4c0d55ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:45:37 +0000 Subject: [PATCH 10/61] 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 | 61 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ----- 44 files changed, 6212 insertions(+), 6318 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b7c9c3d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:09:59.389Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 d97bbf3..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: '56 8 * * 6' - - # 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 + + ```
@@ -291,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -351,17 +344,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index c03e215..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 f46020f..d891b01 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4349906 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 f5588e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index abd5dc5..8b77114 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-null": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-undefined": "^0.1.1", - "@stdlib/ndarray-base-slice-from": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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..bab5712 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 276b1b5277b9e7618dcbafb505d5c6a8e8a94a07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:33:56 +0000 Subject: [PATCH 11/61] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2773cb7..abd5dc5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.1.1", "@stdlib/ndarray-base-slice-from": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 8a8d08bbb86dcb00e4b3deadc23cc371f6bb2c0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:55:35 +0000 Subject: [PATCH 12/61] Remove files --- index.d.ts | 1050 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7232 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 d891b01..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4349906..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bab5712..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c64545d0e11825e960da7caee497cefa889db1cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:56:28 +0000 Subject: [PATCH 13/61] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ----- 44 files changed, 6212 insertions(+), 6323 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ea8a90d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:59:50.234Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 d97bbf3..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4349906 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 f5588e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index abd5dc5..8b77114 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-null": "^0.1.1", - "@stdlib/assert-is-number": "^0.1.1", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-undefined": "^0.1.1", - "@stdlib/ndarray-base-slice-from": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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..63caefd --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 63252b1db7931e4c3bba34eebe92fb96a1f4594f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:14:43 +0000 Subject: [PATCH 14/61] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c781674..24c88c3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.0", "@stdlib/ndarray-base-slice-from": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 64861e02a4484a96ef63a70b3a8ca7bfad5301ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:02:30 +0000 Subject: [PATCH 15/61] Remove files --- index.d.ts | 1050 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7232 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4349906..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.1.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 63caefd..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 68bdd8301584c66bd2c8ce47601d16da37dc5300 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:03:33 +0000 Subject: [PATCH 16/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ----- 43 files changed, 6212 insertions(+), 6326 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 5170ab0..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b4b507b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 f5588e2..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 24c88c3..d6a2b08 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-null": "^0.2.0", - "@stdlib/assert-is-number": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/assert-is-undefined": "^0.2.0", - "@stdlib/ndarray-base-slice-from": "^0.2.0", - "@stdlib/ndarray-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/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "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..fd85a1b --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 41640b131c6b4b456583551648011d40e84fca89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:46:58 +0000 Subject: [PATCH 17/61] 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 6d1390d..e90f3e5 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.0-esm/index.mjs'; ``` #### sliceFrom( x, ...start\[, options] ) @@ -209,7 +209,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.0-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From dfe1ef7b4d61fea529eaccd2e3f40da410247755 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:46:58 +0000 Subject: [PATCH 18/61] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e90f3e5..a359f65 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice-from/tags). For example, + ```javascript import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.0-esm/index.mjs'; ``` @@ -209,7 +214,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.0-esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 4e56a6ab8ea470ea8026ac5c0bdbbba1c0fdd06c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:08:24 +0000 Subject: [PATCH 19/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 6acb6e5..861e2bc 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.1", "@stdlib/ndarray-base-slice-from": "^0.2.1", "@stdlib/ndarray-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 d1f5cff6b6990133819e0234358de29b230f0c91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:46:09 +0000 Subject: [PATCH 20/61] Remove files --- index.d.ts | 1050 --------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7232 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b4b507b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(s){return!(e(s)||n(s)||o(s))}function j(e,n){var o,j,p,f,v,c;if(p={strict:!0},j=arguments.length,!s(e))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",e));if(r(arguments[j-1])){if(d(o=arguments[j-=1],"strict")){if(!i(o.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",o.strict));p.strict=o.strict}if(v=m(e),1===j&&v.length>0)throw new RangeError(l("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",v.join(","),0))}if(t(n)){if(f=n,j>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],c=1;c\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["isInvalidIndex","index","isNumber","isNull","isUndefined","sliceFrom","x","start","options","nargs","opts","args","sh","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","String","base"],"mappings":";;wiCAoDA,SAASA,EAAgBC,GACxB,QACCC,EAAUD,IACVE,EAAQF,IACRG,EAAaH,GAEf,CAiDA,SAASI,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACNI,QAAU,GAEXL,EAAQM,UAAUC,QACZC,EAAeX,GACpB,MAAM,IAAIY,UAAWC,EAAQ,oEAAqEb,IAEnG,GAAKc,EAAeL,UAAWN,EAAM,IAAQ,CAG5C,GAAKY,EADLb,EAAUO,UADVN,GAAS,GAEiB,UAAa,CACtC,IAAMa,EAAWd,EAAQM,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUX,EAAQM,SAEhHJ,EAAKI,OAASN,EAAQM,MACtB,CAED,GADAF,EAAKW,EAAUjB,GACA,IAAVG,GAAeG,EAAGI,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,+HAAgIP,EAAGa,KAAM,KAAO,GAE/K,CACD,GAAKC,EAAmBnB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAIkB,MAAO,gDAIlB,IADAhB,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKiB,KAAMb,UAAWF,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKK,OAAQH,IAC7B,GAAKb,EAAgBW,EAAME,IAC1B,MAAM,IAAIK,UAAWC,EAAQ,oGAAqGU,OAAQlB,EAAME,MAGlJ,OAAOiB,EAAMxB,EAAGK,EAAMD,EAAKI,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fd85a1b..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a1a89620bf3c41490e8f1a8482c449a5dcea5d02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:46:38 +0000 Subject: [PATCH 21/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 43 files changed, 4877 insertions(+), 6321 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..30bce67 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 861e2bc..efbb963 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-null": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-undefined": "^0.2.1", - "@stdlib/ndarray-base-slice-from": "^0.2.1", - "@stdlib/ndarray-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/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-empty": "^0.2.0", - "@stdlib/ndarray-to-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "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..6bc1068 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7fd3818a0b25f00daf42e3b7628fe53eea16fbf3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:16:28 +0000 Subject: [PATCH 22/61] 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 217e704..b32fdd0 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.1-esm/index.mjs'; ``` #### sliceFrom( x, ...start\[, options] ) @@ -209,7 +209,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.1-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 9534b2e07afc26970f5ba5962b8ff4758f7f4f82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:16:29 +0000 Subject: [PATCH 23/61] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b32fdd0..931acc5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice-from/tags). For example, + ```javascript import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.1-esm/index.mjs'; ``` @@ -209,7 +214,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.1-esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From d399570a45f3d13747171d8cdafec6fc1c078abf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:54:06 +0000 Subject: [PATCH 24/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 54c5453..4329a95 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.1", "@stdlib/ndarray-base-slice-from": "^0.2.1", "@stdlib/ndarray-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 0e2c19d28c67c5f45fbd2020606c95eeb1e4e454 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:37:21 +0000 Subject: [PATCH 25/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 30bce67..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6bc1068..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d002d97b857f918f014aaf201f183619d5e1e733 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:37:40 +0000 Subject: [PATCH 26/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6323 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7ba7eb4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:41:55.582Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..01f3ce6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 4329a95..efbb963 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-null": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-undefined": "^0.2.1", - "@stdlib/ndarray-base-slice-from": "^0.2.1", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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..f2c8cf4 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 495b17d55715b3e086fe1b5997f3a76805d4a1d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:11:30 +0000 Subject: [PATCH 27/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 54c5453..4329a95 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.1", "@stdlib/ndarray-base-slice-from": "^0.2.1", "@stdlib/ndarray-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 e6b4a400800aa37aeaa04a66bf0adf4397f98ee8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:36:07 +0000 Subject: [PATCH 28/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 01f3ce6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f2c8cf4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 620258c0d5d2efbb0d2244679c8d6e60082b21c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:36:34 +0000 Subject: [PATCH 29/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6326 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b4ed4c1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:00:05.270Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..01f3ce6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 4329a95..efbb963 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-null": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-undefined": "^0.2.1", - "@stdlib/ndarray-base-slice-from": "^0.2.1", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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..f2c8cf4 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7f8e7b849d11f09d029a2e79e8774c7fd97d5354 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:29:03 +0000 Subject: [PATCH 30/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 54c5453..4329a95 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.1", "@stdlib/ndarray-base-slice-from": "^0.2.1", "@stdlib/ndarray-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 937ab62aa3570aa42d7e1d60685492882f382ec8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:52:04 +0000 Subject: [PATCH 31/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 01f3ce6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f2c8cf4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1209910d0048964f6daacc457acc161191253173 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:52:31 +0000 Subject: [PATCH 32/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 43 files changed, 4877 insertions(+), 6327 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..01f3ce6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 4329a95..efbb963 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-null": "^0.2.1", - "@stdlib/assert-is-number": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-undefined": "^0.2.1", - "@stdlib/ndarray-base-slice-from": "^0.2.1", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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..f2c8cf4 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From becdb8da6a1f6b9e17a9da8b8d4a5740db2f2914 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:46:46 +0000 Subject: [PATCH 33/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index fa370bc..9a78684 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.1", "@stdlib/ndarray-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 41766dc6e89280445926e32efe67d4ab43f18b08 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:01:39 +0000 Subject: [PATCH 34/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 01f3ce6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f2c8cf4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1a56a4159080b6c2dd31c8405a5f05736ab20bf5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:01:55 +0000 Subject: [PATCH 35/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 43 files changed, 4877 insertions(+), 6438 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3e52b8b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 9a78684..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.1", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "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..5a486a1 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 111c514d4979319332c76c4d36928d4cbdb0f724 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:11:03 +0000 Subject: [PATCH 36/61] 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 c5ed780..ba3ea9a 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.2-esm/index.mjs'; ``` #### sliceFrom( x, ...start\[, options] ) @@ -209,7 +209,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.2-esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 07a458cace538965be79815dace9691186adeafb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:11:04 +0000 Subject: [PATCH 37/61] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba3ea9a..46c71be 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice-from/tags). For example, + ```javascript import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.2-esm/index.mjs'; ``` @@ -209,7 +214,7 @@ arr = ndarray2array( y ); 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 sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@v0.2.2-esm/index.mjs'; +import sliceFrom from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice-from@esm/index.mjs'; // Create a linear ndarray buffer: var buf = zeroTo( 27 ); From 03b1d6d9d7b556c9d30266cbd302cc1242e0c2a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:00:08 +0000 Subject: [PATCH 38/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 4077441..eb48699 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 1e01dad0394e3c80e37b357e224c46528fbe7010 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:55:16 +0000 Subject: [PATCH 39/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3e52b8b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5a486a1..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b3c731d6afbdae7cf3c082ce5fff51b56c33dbe7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:55:38 +0000 Subject: [PATCH 40/61] 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 | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6414 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 67a2b29..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:52:33.169Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c9f1ce --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index eb48699..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 4eb6eb033b76730dcbdfd69361cc0cf77f09f51b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:24:21 +0000 Subject: [PATCH 41/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index f66ffd9..f402d21 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 4216047c3c83e0e8560958f54f4e22acc5cb60e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:48:27 +0000 Subject: [PATCH 42/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c9f1ce..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0a6faded977358d67a43412c0f34cc3b9c2d2ab3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:48:48 +0000 Subject: [PATCH 43/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6439 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a8bfefe..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:19:23.299Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c9f1ce --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index f402d21..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 47eeec26d8ff3212ecccf5f476e37ca544877eaa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:41:14 +0000 Subject: [PATCH 44/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index f66ffd9..f402d21 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 0dfd1d19fa5029bdbcd34d31083759a021e2e884 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:20:06 +0000 Subject: [PATCH 45/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c9f1ce..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 70c8969f5809196ff3cb5cdd6600def83ec1fdb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:20:31 +0000 Subject: [PATCH 46/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6439 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4389e5d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:31:30.978Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c9f1ce --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index f402d21..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From ad28dd33a025d2239fca54043f00c16562302d06 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:28:01 +0000 Subject: [PATCH 47/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index f66ffd9..f402d21 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 cd5de4e61a2b5132b967b860d9d37faaac7ec6a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:25:47 +0000 Subject: [PATCH 48/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c9f1ce..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5283d3ecadb507e1d333bd5fcaf08201b200d82d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:26:04 +0000 Subject: [PATCH 49/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------- 44 files changed, 4877 insertions(+), 6439 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ff8886f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:34:42.107Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c9f1ce --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index f402d21..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 9fc9f88b6500c67fc754ebc970fb4564f90fd7d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:30:33 +0000 Subject: [PATCH 50/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 0129a2b..63aa813 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 8c98be214236d8ca79fceedb3517bffc1b38c1d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:35:35 +0000 Subject: [PATCH 51/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c9f1ce..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 12125bfecedcd9dee81f73429aa6b84d791c9b6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:36:20 +0000 Subject: [PATCH 52/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------ 45 files changed, 4877 insertions(+), 6544 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0fc76b1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:29:55.720Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d7baaef..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7c9f1ce --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 63aa813..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From af4aecd430414a503620688759755c04ba4adebd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:07:18 +0000 Subject: [PATCH 53/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 0129a2b..63aa813 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 c9d4905d1e0806a1674b4fe3fa41e4d60b39193f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:28:09 +0000 Subject: [PATCH 54/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7c9f1ce..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e252d902ab990113c39e10741b5b8ae6a07212c5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 19 May 2025 02:28:38 +0000 Subject: [PATCH 55/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------ 45 files changed, 4877 insertions(+), 6547 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5e33865..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-19T02:01:56.131Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ec02994..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..215ecb7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 63aa813..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 3a0103d340d888fd0cec748c10e8bce7e1c60b8a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Jun 2025 00:46:14 +0000 Subject: [PATCH 56/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 0129a2b..63aa813 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 a9e5e5b9d2b502cb504d8a3bdfcc0298ca62be0d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Jun 2025 00:47:43 +0000 Subject: [PATCH 57/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 215ecb7..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 352cbb0b7fba6334a98eb932b72f400e74078249 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 9 Jun 2025 00:48:46 +0000 Subject: [PATCH 58/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------ 45 files changed, 4877 insertions(+), 6547 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8c2ee45..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-09T00:45:21.804Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ec02994..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..215ecb7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 63aa813..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 6ec6ae91efe0497c3e69a9871446ef4f202cac5e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 01:25:50 +0000 Subject: [PATCH 59/61] Transform error messages --- lib/main.js | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/main.js b/lib/main.js index f5588e2..d071963 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var isUndefined = require( '@stdlib/assert-is-undefined' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var getShape = require( '@stdlib/ndarray-shape' ); var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // FUNCTIONS // @@ -118,26 +118,26 @@ function sliceFrom( x, start ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1mx4f', x ) ); } if ( isPlainObject( arguments[ nargs-1 ] ) ) { nargs -= 1; options = arguments[ nargs ]; if ( hasOwnProp( options, 'strict' ) ) { if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) ); + throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) ); + throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); } } if ( isArrayLikeObject( start ) ) { args = start; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1mx0m') ); } } else { args = []; @@ -147,7 +147,7 @@ function sliceFrom( x, start ) { } for ( i = 0; i < args.length; i++ ) { if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) ); + throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); } } return base( x, args, opts.strict, false ); diff --git a/package.json b/package.json index 0129a2b..63aa813 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/assert-is-undefined": "^0.2.2", "@stdlib/ndarray-base-slice-from": "^0.2.2", "@stdlib/ndarray-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 37627365e2ede3b37059f0e1c05b4cc9d587b1a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:08:39 +0000 Subject: [PATCH 60/61] Remove files --- index.d.ts | 1050 ----------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5897 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 17366b6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1050 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Starting index. -* -* ## Notes -* -* - A value of `null` or `undefined` indicates to include all elements along a corresponding dimension. -* - A negative integer indicates to resolve a starting index relative to the last element along a corresponding dimension, with the last element having index `-1`. -*/ -type StartArgument = null | undefined | number; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, start: ArrayLike, options?: Options ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float64ndarray, ...start: Array ): float64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, start: ArrayLike, options?: Options ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -declare function sliceFrom( x: float32ndarray, ...start: Array ): float32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, start: ArrayLike, options?: Options ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int32ndarray, ...start: Array ): int32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, start: ArrayLike, options?: Options ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int16ndarray, ...start: Array ): int16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, start: ArrayLike, options?: Options ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: int8ndarray, ...start: Array ): int8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, start: ArrayLike, options?: Options ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint32ndarray, ...start: Array ): uint32ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, start: ArrayLike, options?: Options ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint16ndarray, ...start: Array ): uint16ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, start: ArrayLike, options?: Options ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8ndarray, ...start: Array ): uint8ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, start: ArrayLike, options?: Options ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: uint8cndarray, ...start: Array ): uint8cndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, start: ArrayLike, options?: Options ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex128ndarray, ...start: Array ): complex128ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, start: ArrayLike, options?: Options ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function sliceFrom( x: complex64ndarray, ...start: Array ): complex64ndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, start: ArrayLike, options?: Options ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: genericndarray, ...start: Array ): genericndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 = [ 1, null ]; -* var y = sliceFrom( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, start: ArrayLike, options?: Options ): typedndarray; - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param x - input array -* @param start - starting indices (inclusive) -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3, 4 ], [ 5, 6 ] ] -*/ -declare function sliceFrom( x: typedndarray, ...start: Array ): typedndarray; - - -// EXPORTS // - -export = sliceFrom; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 215ecb7..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 s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fefd8f2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From daf4c89e5cda5b582f5ec438f0a7312822f6115e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Jun 2025 02:09:12 +0000 Subject: [PATCH 61/61] 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 | 103 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 86 - benchmark/benchmark.js | 786 --- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 61 - docs/types/test.ts | 237 - examples/index.js | 56 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 159 - package.json | 75 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1480 ------ 45 files changed, 4877 insertions(+), 6547 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 65b0cfd..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-06-30T01:14:21.902Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ec02994..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 df278e3..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from) 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 7b4b339..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: '56 8 * * 6' - - # 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 + + ```
@@ -293,7 +284,7 @@ var a3 = ndarray2array( y3 ); ## 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]. @@ -356,17 +347,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice-from/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice +[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from +[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray-slice-dimension-from/tree/esm -[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to +[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray-slice-to/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 9cad51d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,separate_arguments', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], null, null ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,array', function benchmark( b ) { - var values; - var v; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], [ null, null ] ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index c3bbf29..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,786 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var sliceFrom = 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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.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 = []; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2 ], 'row-major' ) - ]; - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2 ], { 'dtype': 'float64' } ), - empty( [ 2 ], { 'dtype': 'float32' } ), - empty( [ 2 ], { 'dtype': 'int32' } ), - empty( [ 2 ], { 'dtype': 'complex128' } ), - empty( [ 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20 ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) - ]; - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( '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 = [ 1, 1, 1, 1, 1 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), - baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) - ]; - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,non-base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), - empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = [ 1, 1, 1, 20, null ]; - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = sliceFrom( values[ i%values.length ], s, opts ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an ndarray' ); - } - } - b.toc(); - if ( !isndarrayLike( v ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0efacd0..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from" -%% click B href "https://github.com/stdlib-js/ndarray-slice-from/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice-from/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice-from/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice-from/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice-from/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice-from -[production-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice-from/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice-from/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice-from/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 d4193d7..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sliceFrom from '../docs/types/index'; -export = sliceFrom; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9eab9a0..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var l=function(r,i){return function(){return i||r((i={exports:{}}).exports,i),i.exports}};var m=l(function(T,v){"use strict";var c=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-array-like-object"),g=require("@stdlib/assert-is-plain-object"),h=require("@stdlib/assert-is-number").isPrimitive,d=require("@stdlib/assert-is-boolean").isPrimitive,p=require("@stdlib/assert-is-null"),q=require("@stdlib/assert-is-undefined"),b=require("@stdlib/assert-has-own-property"),w=require("@stdlib/ndarray-shape"),y=require("@stdlib/ndarray-base-slice-from"),s=require("@stdlib/string-format");function E(r){return!(h(r)||p(r)||q(r))}function N(r,i){var n,t,o,a,u,e;if(o={strict:!0},t=arguments.length,!c(r))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",r));if(g(arguments[t-1])){if(t-=1,n=arguments[t],b(n,"strict")){if(!d(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=w(r),t===1&&u.length>0)throw new RangeError(s("invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.",u.join(","),0))}if(f(i)){if(a=i,t>2)throw new Error("invalid invocation. Too many arguments.")}else for(a=[],e=1;e\n*\n* var sh = x.shape;\n* // returns [ 3, 2 ]\n*\n* var arr = ndarray2array( x );\n* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*\n* var y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( 'invalid argument. Number of indices does not match the number of array dimensions. Array shape: (%s). Number of indices: %u.', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Each index argument must be either an integer, null, or undefined. Value: `%s`.', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sliceFrom;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 shifted view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice-from\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var sliceFrom = require( '@stdlib/ndarray-slice-from' );\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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAS,QAAS,wBAAyB,EAC3CC,EAAc,QAAS,6BAA8B,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,uBAAwB,EAC5CC,EAAO,QAAS,iCAAkC,EAClDC,EAAS,QAAS,uBAAwB,EAoB9C,SAASC,EAAgBC,EAAQ,CAChC,MAAO,EACNT,EAAUS,CAAM,GAChBP,EAAQO,CAAM,GACdN,EAAaM,CAAM,EAErB,CAiDA,SAASC,EAAWC,EAAGC,EAAQ,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAH,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACjB,EAAec,CAAE,EACtB,MAAM,IAAI,UAAWJ,EAAQ,oEAAqEI,CAAE,CAAE,EAEvG,GAAKZ,EAAe,UAAWe,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACZ,EAAWY,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWN,EAAQ,+DAAgE,SAAUM,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKZ,EAAUM,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYV,EAAQ,+HAAgIU,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAEpL,CACA,GAAKnB,EAAmBc,CAAM,GAE7B,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAI5D,KADAE,EAAO,CAAC,EACFE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAK,KAAM,UAAWE,CAAE,CAAE,EAG5B,IAAMA,EAAI,EAAGA,EAAIF,EAAK,OAAQE,IAC7B,GAAKV,EAAgBQ,EAAME,CAAE,CAAE,EAC9B,MAAM,IAAI,UAAWX,EAAQ,oGAAqG,OAAQS,EAAME,CAAE,CAAE,CAAE,CAAE,EAG1J,OAAOZ,EAAMK,EAAGK,EAAMD,EAAK,OAAQ,EAAM,CAC1C,CAKAnB,EAAO,QAAUc,ICtGjB,IAAIS,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isArrayLikeObject", "isPlainObject", "isNumber", "isBoolean", "isNull", "isUndefined", "hasOwnProp", "getShape", "base", "format", "isInvalidIndex", "index", "sliceFrom", "x", "start", "options", "nargs", "opts", "args", "sh", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 60e829a..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,61 +0,0 @@ - -{{alias}}( x, ...start[, options] ) - Returns a read-only shifted view of an input ndarray. - - The function supports two (mutually exclusive) means of providing starting - indices: - - 1. Providing a single array containing start arguments. - 2. Providing start arguments as separate arguments. - - An individual start argument must be either an integer, null, or undefined. - - In all cases, the number of start indices must match the number of array - dimensions. - - If providing an array of start arguments, no other start arguments should be - provided. - - Mixing function invocation styles (e.g., providing an array of start - arguments followed by additional start arguments) is not supported. - - Parameters - ---------- - x: ndarray - Input array. - - start: ...null|void|integer - Starting indices (inclusive). If an element is either `null` or - `undefined`, the function returns a view containing all elements along - that dimension. A negative integer indicates to resolve a starting index - relative to the last element along a corresponding dimension, with the - last element having index `-1`. - - options: Object (optional) - Options. - - options.strict: boolean (optional) - Boolean indicating whether to enforce strict bounds checking. - Default: true. - - Returns - ------- - out: ndarray - Output array view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var y = {{alias}}( x, 0, 1 ) - - > y.shape - [ 2, 1 ] - > {{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 26017f2..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sliceFrom = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = [ 1, null ]; - - sliceFrom( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - sliceFrom( empty( 'float64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float64ndarray - sliceFrom( empty( 'float32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType float32ndarray - sliceFrom( empty( 'complex128', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex128ndarray - sliceFrom( empty( 'complex64', sh, order ), 1, null, { 'strict': false } ); // $ExpectType complex64ndarray - sliceFrom( empty( 'int32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int32ndarray - sliceFrom( empty( 'int16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int16ndarray - sliceFrom( empty( 'int8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType int8ndarray - sliceFrom( empty( 'uint32', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint32ndarray - sliceFrom( empty( 'uint16', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint16ndarray - sliceFrom( empty( 'uint8', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8ndarray - sliceFrom( empty( 'uint8c', sh, order ), 1, null, { 'strict': false } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = [ 1, null ]; - - sliceFrom( '10', s ); // $ExpectError - sliceFrom( 10, s ); // $ExpectError - sliceFrom( false, s ); // $ExpectError - sliceFrom( true, s ); // $ExpectError - sliceFrom( null, s ); // $ExpectError - sliceFrom( [], s ); // $ExpectError - sliceFrom( {}, s ); // $ExpectError - sliceFrom( ( x: number ): number => x, s ); // $ExpectError - - sliceFrom( '10', 1, null ); // $ExpectError - sliceFrom( 10, 1, null ); // $ExpectError - sliceFrom( false, 1, null ); // $ExpectError - sliceFrom( true, 1, null ); // $ExpectError - sliceFrom( null, 1, null ); // $ExpectError - sliceFrom( [], 1, null ); // $ExpectError - sliceFrom( {}, 1, null ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null ); // $ExpectError - - sliceFrom( '10', s, { 'strict': false } ); // $ExpectError - sliceFrom( 10, s, { 'strict': false } ); // $ExpectError - sliceFrom( false, s, { 'strict': false } ); // $ExpectError - sliceFrom( true, s, { 'strict': false } ); // $ExpectError - sliceFrom( null, s, { 'strict': false } ); // $ExpectError - sliceFrom( [], s, { 'strict': false } ); // $ExpectError - sliceFrom( {}, s, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, s, { 'strict': false } ); // $ExpectError - - sliceFrom( '10', 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( 10, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( false, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( true, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( null, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( [], 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( {}, 1, null, { 'strict': false } ); // $ExpectError - sliceFrom( ( x: number ): number => x, 1, null, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, '5' ); // $ExpectError - sliceFrom( x, false ); // $ExpectError - sliceFrom( x, true ); // $ExpectError - sliceFrom( x, [ '5' ] ); // $ExpectError - sliceFrom( x, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid start argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - sliceFrom( x, 1, '5' ); // $ExpectError - sliceFrom( x, 1, false ); // $ExpectError - sliceFrom( x, 1, true ); // $ExpectError - sliceFrom( x, 1, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, '5' ); // $ExpectError - sliceFrom( x, 1, null, false ); // $ExpectError - sliceFrom( x, 1, null, true ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, ( x: number ): number => x, { 'strict': false } ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5' ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ] ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x ); // $ExpectError - - sliceFrom( x, 1, null, undefined, -2, 0, '5', { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, false, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, true, { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, [ '5' ], { 'strict': false } ); // $ExpectError - sliceFrom( x, 1, null, undefined, -2, 0, ( x: number ): number => x, { 'strict': false } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, '5' ); // $ExpectError - sliceFrom( x, s, 5 ); // $ExpectError - sliceFrom( x, s, true ); // $ExpectError - sliceFrom( x, s, false ); // $ExpectError - sliceFrom( x, s, null ); // $ExpectError - sliceFrom( x, s, [ '5' ] ); // $ExpectError - sliceFrom( x, s, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `strict` option which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom( x, s, { 'strict': '5' } ); // $ExpectError - sliceFrom( x, s, { 'strict': 5 } ); // $ExpectError - sliceFrom( x, s, { 'strict': null } ); // $ExpectError - sliceFrom( x, s, { 'strict': [ '5' ] } ); // $ExpectError - sliceFrom( x, s, { 'strict': {} } ); // $ExpectError - sliceFrom( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = [ 1, null ]; - - sliceFrom(); // $ExpectError - sliceFrom( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 4d1302f..0000000 --- a/examples/index.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'; - -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var sliceFrom = require( './../lib' ); - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get the last two rows of each matrix: -var y1 = sliceFrom( x, null, 1, null ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ [ 3, 4, 5 ], [ 6, 7, 8 ] ], [ [ 12, 13, 14 ], [ 15, 16, 17 ] ], [ [ 21, 22, 23 ], [ 24, 25, 26 ] ] ] - -// Get the last two rows and columns of each matrix: -var y2 = sliceFrom( x, null, 1, 1 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ [ 4, 5 ], [ 7, 8 ] ], [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] - -// Get the last two 2x2 matrices: -var y3 = sliceFrom( x, 1, 1, 1 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ [ 13, 14 ], [ 16, 17 ] ], [ [ 22, 23 ], [ 25, 26 ] ] ] 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 fd24367..17366b6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; import { ArrayLike } from '@stdlib/types/array'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..215ecb7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-number@v0.2.2-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-null@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-undefined@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice-from@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var f,a,v,c,g,x,b;if(v={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1mx4f",h));if(r(arguments[a-1])){if(d(f=arguments[a-=1],"strict")){if(!i(f.strict))throw new TypeError(l("1mx2o","strict",f.strict));v.strict=f.strict}if(g=o(h),1===a&&g.length>0)throw new RangeError(l("1mxFE",g.join(","),0))}if(t(p)){if(c=p,a>2)throw new Error(l("1mx0m"))}else for(c=[],x=1;x\n*\n* var sh = x.shape;\n* // returns [ 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 y = sliceFrom( x, 1, null );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]\n*/\nfunction sliceFrom( x, start ) {\n\tvar options;\n\tvar nargs;\n\tvar opts;\n\tvar args;\n\tvar sh;\n\tvar i;\n\n\topts = {\n\t\t'strict': true\n\t};\n\tnargs = arguments.length;\n\tif ( !isndarrayLike( x ) ) {\n\t\tthrow new TypeError( format( '1mx4f', x ) );\n\t}\n\tif ( isPlainObject( arguments[ nargs-1 ] ) ) {\n\t\tnargs -= 1;\n\t\toptions = arguments[ nargs ];\n\t\tif ( hasOwnProp( options, 'strict' ) ) {\n\t\t\tif ( !isBoolean( options.strict ) ) {\n\t\t\t\tthrow new TypeError( format( '1mx2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isArrayLikeObject( start ) ) {\n\t\targs = start;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1mx0m') );\n\t\t}\n\t} else {\n\t\targs = [];\n\t\tfor ( i = 1; i < nargs; i++ ) {\n\t\t\targs.push( arguments[ i ] );\n\t\t}\n\t}\n\tfor ( i = 0; i < args.length; i++ ) {\n\t\tif ( isInvalidIndex( args[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '1mxFF', String( args[ i ] ) ) );\n\t\t}\n\t}\n\treturn base( x, args, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default sliceFrom;\n"],"names":["sliceFrom","x","start","options","nargs","opts","args","sh","i","index","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isArrayLikeObject","Error","push","isNumber","isNull","isUndefined","String","base"],"mappings":";;ijCA2GA,SAASA,EAAWC,EAAGC,GACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EA7DoBC,EAmExB,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAmBpB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDE,EAAI,EAAGA,EAAIJ,EAAOI,IACvBF,EAAKkB,KAAMb,UAAWH,IAGxB,IAAMA,EAAI,EAAGA,EAAIF,EAAKM,OAAQJ,IAC7B,GAhGuBC,EAgGFH,EAAME,KA9F3BiB,EAAUhB,IACViB,EAAQjB,IACRkB,EAAalB,IA6FZ,MAAM,IAAIK,UAAWC,EAAQ,QAASa,OAAQtB,EAAME,MAGtD,OAAOqB,EAAM5B,EAAGK,EAAMD,EAAKK,QAAQ,EACpC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 12095ae..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 shifted view of an input ndarray. -* -* @module @stdlib/ndarray-slice-from -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var sliceFrom = require( '@stdlib/ndarray-slice-from' ); -* -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.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 d071963..0000000 --- a/lib/main.js +++ /dev/null @@ -1,159 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isPlainObject = require( '@stdlib/assert-is-plain-object' ); -var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive; -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert-is-null' ); -var isUndefined = require( '@stdlib/assert-is-undefined' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var base = require( '@stdlib/ndarray-base-slice-from' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// FUNCTIONS // - -/** -* Tests whether a starting index argument is invalid. -* -* @private -* @param {*} index - index argument -* @returns {boolean} boolean indicating if an argument is invalid -* -* @example -* var bool = isInvalidIndex( 4 ); -* // returns false -* -* @example -* var bool = isInvalidIndex( {} ); -* // returns true -*/ -function isInvalidIndex( index ) { - return !( - isNumber( index ) || - isNull( index ) || - isUndefined( index ) - ); -} - - -// MAIN // - -/** -* Returns a read-only shifted view of an input ndarray. -* -* @param {ndarray} x - input array -* @param {...(null|integer|undefined)} start - starting indices (inclusive) -* @param {Options} [options] - options -* @param {boolean} [options.strict] - boolean indicating whether to enforce strict bounds checking -* @throws {TypeError} first argument must be an ndarray -* @throws {TypeError} must provide valid starting indices -* @throws {Error} insufficient arguments -* @throws {Error} too many arguments -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} number of starting indices must match the number of array dimensions -* @throws {RangeError} index exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* 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 y = sliceFrom( x, 1, null ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -*/ -function sliceFrom( x, start ) { - var options; - var nargs; - var opts; - var args; - var sh; - var i; - - opts = { - 'strict': true - }; - nargs = arguments.length; - if ( !isndarrayLike( x ) ) { - throw new TypeError( format( '1mx4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1mx2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1mxFE', sh.join( ',' ), 0 ) ); - } - } - if ( isArrayLikeObject( start ) ) { - args = start; - if ( nargs > 2 ) { - throw new Error( format('1mx0m') ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - for ( i = 0; i < args.length; i++ ) { - if ( isInvalidIndex( args[ i ] ) ) { - throw new TypeError( format( '1mxFF', String( args[ i ] ) ) ); - } - } - return base( x, args, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = sliceFrom; diff --git a/package.json b/package.json index 63aa813..c2e74b3 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only shifted view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-null": "^0.2.2", - "@stdlib/assert-is-number": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-undefined": "^0.2.2", - "@stdlib/ndarray-base-slice-from": "^0.2.2", - "@stdlib/ndarray-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/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.3.0", - "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..fefd8f2 --- /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 09e5a06..0000000 --- a/test/test.js +++ /dev/null @@ -1,1480 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 zeroTo = require( '@stdlib/array-base-zero-to' ); -var typedarray = require( '@stdlib/array-typed' ); -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 sliceFrom = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sliceFrom, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (index arguments)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( value, null, null ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (array)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = [ null ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=1)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided a `strict` option which is not a boolean (index argument, ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, s, { - 'strict': value - }); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=2)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid index argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = zeros( [ 1, 1, 1 ] ); - s = null; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sliceFrom( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (index arguments, options)', function test( t ) { - var values; - var stop; - var i; - - values = [ - zeros( [] ), - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - stop = [ - [ null ], - [ null, null, null ], - [ null ], - [ null, null ], - [ null, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], stop[ i ] ), RangeError, 'throws an error when provided ' + stop[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return sliceFrom( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return sliceFrom( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of index arguments does not match the number of array dimensions (no index arguments, options)', function test( t ) { - var values; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided shape (' + values[ i ].shape.join( ',' ) + ')' ); - } - t.end(); - - function badValue( x ) { - return function badValue() { - sliceFrom( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a starting index exceeds array bounds', function test( t ) { - var values; - var start; - var i; - - values = [ - zeros( [ 1 ] ), - zeros( [ 1, 1 ] ), - zeros( [ 1, 1, 1 ] ), - zeros( [ 1, 1, 1, 1 ] ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ] - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValues( values[ i ], start[ i ] ), RangeError, 'throws an error when provided ' + start[ i ].toString() ); - } - t.end(); - - function badValues( x, s ) { - return function badValues() { - sliceFrom( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a starting index exceeds array bounds', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 10 ], - [ null, 20 ], - [ 20, null, null ], - [ 20, 20, null, null ], - [ null, null, null, null, 10 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns an empty array when a starting index is one more than the last index along a dimension', function test( t ) { - var actual; - var values; - var start; - 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' } ) - ]; - - start = [ - [ 1 ], - [ null, 1 ], - [ 1, null, null ], - [ 1, 1, null, null ], - [ null, null, null, null, 1 ] - ]; - for ( i = 0; i < values.length; i++ ) { - actual = sliceFrom( values[ i ], start[ i ] ); - 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 = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base; no index arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = sliceFrom( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = []; - - actual = sliceFrom( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - s = [ 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - s = [ -4 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=1, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - 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 ); - - actual = sliceFrom( x, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - } - - actual = sliceFrom( x, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - actual = sliceFrom( x, -4 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 4, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ void 0, void 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - s = [ 0, 0 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 2, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, 1 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=2, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - actual = sliceFrom( x, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, void 0, void 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 4, 6, 8 ], - [ 10, 12, 14 ], - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - - actual = sliceFrom( x, 0, 0 ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 2, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 16, 18, 20 ], - [ 22, 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 6, 8 ], - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, 1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 3, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ 12, 14 ], - [ 18, 20 ], - [ 24, 26 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - 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 = [ null, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - s = [ 1, null, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, 1, null ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ null, null, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - s = [ 1, -2, 2 ]; - actual = sliceFrom( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a shifted view of a provided input array (ndims=3, index arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - - 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 ); - - actual = sliceFrom( x, null, null, null ); - - 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' ); - t.strictEqual( isReadOnly( actual ), true, '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' ); - - actual = sliceFrom( x, 1, null, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 34, 36, 38 ], - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, 1, null ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 16, 18, 20 ], - [ 22, 24, 26 ], - [ 28, 30, 32 ] - ], - [ - [ 40, 42, 44 ], - [ 46, 48, 50 ], - [ 52, 54, 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, null, null, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 14 ], - [ 20 ], - [ 26 ], - [ 32 ] - ], - [ - [ 38 ], - [ 44 ], - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - actual = sliceFrom( x, 1, -2, 2 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 1 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - expected = [ - [ - [ 50 ], - [ 56 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -});